import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



N,M = list(map(int,input().split()))

XY = [[int(x) for x in input().split()] for _ in range(M)]



# 各時点でのボールの合計個数、赤の最大個数（0 or 1）を持つ



ball = [None] + [1] * N

red = [None] + [1] + [0] * (N-1)



for x,y in XY:

    if red[x] == 0:

        # 必ず白をうつす

        ball[x] -= 1

        ball[y] += 1

        continue

    if red[x] == 1:

        if ball[x] == 1:

            # 必ず赤をうつす

            red[x] = 0

            ball[x] -= 1

            red[y] = 1

            ball[y] += 1

        else:

            # どちらかをうつす

            ball[x] -= 1

            ball[y] += 1

            red[y] = 1



answer = sum(red[1:])

print(answer)



ball



red



import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N,M = list(map(int,readline().split()))

m = list(map(int,read().split()))

XY = list(zip(m,m))



red = [0] + [1] + [0] * (N-1)

ball = [0] + [1] * N



for x,y in XY:

    if red[x]:

        red[y] = 1

    ball[x] -= 1; ball[y] += 1

    if not ball[x]:

        red[x] = 0



answer = sum(red)

print(answer)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
XY = [[int(x) for x in input().split()] for _ in range(M)]
# 各時点でのボールの合計個数、赤の最大個数（0 or 1）を持つ
ball = [None] + [1] * N
red = [None] + [1] + [0] * (N - 1)
for x, y in XY:
    if red[x] == 0:
        # 必ず白をうつす
        ball[x] -= 1
        ball[y] += 1
        continue
    if red[x] == 1:
        if ball[x] == 1:
            # 必ず赤をうつす
            red[x] = 0
            ball[x] -= 1
            red[y] = 1
            ball[y] += 1
        else:
            # どちらかをうつす
            ball[x] -= 1
            ball[y] += 1
            red[y] = 1
answer = sum(red[1:])
print(answer)
ball
red

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
m = list(map(int, read().split()))
XY = list(zip(m, m))
red = [0] + [1] + [0] * (N - 1)
ball = [0] + [1] * N
for x, y in XY:
    if red[x]:
        red[y] = 1
    ball[x] -= 1
    ball[y] += 1
    if not ball[x]:
        red[x] = 0
answer = sum(red)
print(answer)

-input = sys.stdin.readline -sys.setrecursionlimit(10**7) -N, M = list(map(int, input().split())) -XY = [[int(x) for x in input().split()] for _ in range(M)] -# 各時点でのボールの合計個数、赤の最大個数（0 or 1）を持つ -ball = [None] + [1] * N -red = [None] + [1] + [0] * (N - 1) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N, M = list(map(int, readline().split())) +m = list(map(int, read().split())) +XY = list(zip(m, m)) +red = [0] + [1] + [0] * (N - 1) +ball = [0] + [1] * N -    if red[x] == 0: -        # 必ず白をうつす -        ball[x] -= 1 -        ball[y] += 1 -        continue -    if red[x] == 1: -        if ball[x] == 1: -            # 必ず赤をうつす -            red[x] = 0 -            ball[x] -= 1 -            red[y] = 1 -            ball[y] += 1 -        else: -            # どちらかをうつす -            ball[x] -= 1 -            ball[y] += 1 -            red[y] = 1 -answer = sum(red[1:]) +    if red[x]: +        red[y] = 1 +    ball[x] -= 1 +    ball[y] += 1 +    if not ball[x]: +        red[x] = 0 +answer = sum(red) -ball -red