You'll need to build the logic that feeds the Stop Block input using
relational operators or "detect blocks"
and use blocks with state to keep track of the counts.
The state needs can be managed with unit delays and switch blocks
or you can use the discrete integrator block configured to Accumulator mode (which does not multiply inputs by sample time).