atcoder#AGC002B. [AGC002B] Box and Ball

[AGC002B] Box and Ball

Problem Statement

We have NN boxes, numbered 11 through NN. At first, box 11 contains one red ball, and each of the other boxes contains one white ball.

Snuke will perform the following MM operations, one by one. In the ii-th operation, he randomly picks one ball from box xix_i, then he puts it into box yiy_i.

Find the number of boxes that may contain the red ball after all operations are performed.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • 1xi,yiN1 \leq x_i,y_i \leq N
  • xiyix_i \neq y_i
  • Just before the ii-th operation is performed, box xix_i contains at least 11 ball.

Input

The input is given from Standard Input in the following format:

NN MM

x1x_1 y1y_1

::

xMx_M yMy_M

Output

Print the number of boxes that may contain the red ball after all operations are performed.

3 2
1 2
2 3
2

Just after the first operation, box 11 is empty, box 22 contains one red ball and one white ball, and box 33 contains one white ball.

Now, consider the second operation. If Snuke picks the red ball from box 22, the red ball will go into box 33. If he picks the white ball instead, the red ball will stay in box 22. Thus, the number of boxes that may contain the red ball after all operations, is 22.

3 3
1 2
2 3
2 3
1

All balls will go into box 33.

4 4
1 2
2 3
4 1
3 4
3