Problem:
   Problem Statement We have N boxes, numbered 1 through N . At first, box 1 contains one red ball, and each of the other boxes contains one white ball.  Snuke will perform the following M operations, one by one. In the i -th operation, he randomly picks one ball from box x_i , then he puts it into box y_i .  Find the number of boxes that may contain the red ball after all operations are performed.      Constraints  2≤N≤10^5  1≤M≤10^5  1≤x_i,y_i≤N  x_i≠y_i  Just before the i -th operation is performed, box x_i contains at least 1 ball.         Input The input is given from Standard Input in the following format:  N  M  x_1  y_1  :  x_M  y_M       Output Print the number of boxes that may contain the red ball after all operations are performed.        Sample Input 1 3 2
1 2
2 3      Sample Output 1 2  Just after the first operation, box 1 is empty, box 2 contains one red ball and one white ball, and box 3 contains one white ball.  Now, consider the second operation. If Snuke picks the red ball from box 2 , the red ball will go into box 3 . If he picks the white ball instead, the red ball will stay in box 2 .
Thus, the number of boxes that may contain the red ball after all operations, is 2 .       Sample Input 2 3 3
1 2
2 3
2 3      Sample Output 2 1  All balls will go into box 3 .       Sample Input 3 4 4
1 2
2 3
4 1
3 4      Sample Output 3 3

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n, m = map(int, input().split())

    red = [0 for _ in range(n)]
    red[0] = 1
    balls = [1 for _ in range(n)]

    for _ in range(m):
        x, y = map(int, input().split())

        if red[x - 1] == 1:
            red[y - 1] = 1

        balls[x - 1] -= 1
        balls[y - 1] += 1

        if balls[x - 1] == 0:
            red[x - 1] = 0

    print(sum(red))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例1(self):
        input = """3 2
1 2
2 3"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例2(self):
        input = """3 3
1 2
2 3
2 3"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例3(self):
        input = """4 4
1 2
2 3
4 1
3 4"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
n,m=map(int,input().split())
xy=[]
for _ in range(m):
  xy.append(list(map(int,input().split())))

ans=1
n0=xy[0][1]
rb=[1]
rb[1:1]=[0]*(n-1)
cb=[1]*n
for i in range(m):
  if rb[xy[i][0]-1]==1:
    rb[xy[i][1]-1]=1
  cb[xy[i][1]-1]+=1
  cb[xy[i][0]-1]-=1
  if cb[xy[i][0]-1]==0:
    rb[xy[i][0]-1]=0

print(sum(rb))

Solution (Python):
import sys

n, m, *xy = map(int, sys.stdin.buffer.read().split())
xy = list(zip(xy[0::2], xy[1::2]))
counts = [1] * n
can = [False] * n
can[0] = True

for x, y in xy:
    x -= 1
    y -= 1
    counts[x] -= 1
    counts[y] += 1
    if can[x]:
        can[y] = True
        if counts[x] == 0:
            can[x] = False

print(sum(can))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, M = map(int, input().split())
    quantity = [1] * N
    red = [True] + [False] * (N - 1)

    for i in range(M):
        x, y = map(int, input().split())
        quantity[x - 1] -= 1
        quantity[y - 1] += 1
        if red[x - 1] == True:
            red[y - 1] = True

        if quantity[x - 1] == 0:
            red[x - 1] = False
    print(red.count(True))


resolve()

Solution (Python):
N,M= map(int,input().split())

x = []
y = []
for i in range(M):
  xi, yi = input().split()
  x.append(int(xi))
  y.append(int(yi))

L=[]
for i in range(N):
  L.append(1)
R=[1]
for i in range(N-1):
  R.append(0)



for i in range(M):
  if R[x[i]-1]==1 and L[x[i]-1]==1:
    R[x[i]-1]=0
    L[x[i]-1]=0
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[x[i]-1]==1 and L[x[i]-1]>=1:
    L[x[i]-1]=L[x[i]-1]-1
    R[y[i]-1]=1
    L[y[i]-1]=L[y[i]-1]+1
  elif R[x[i]-1]==0 and L[x[i]-1]>=1:
    L[x[i]-1]=L[x[i]-1]-1
    L[y[i]-1]=L[y[i]-1]+1
  
    

print(R.count(1))

Solution (Python):
N,M = map(int,input().split())
a = [1]+[0]*(N-1)
b = [1]*N

for i in range(M):
  x,y = map(int,input().split())
  if a[x-1]==1 and b[x-1]==1:
    a[x-1]=0
    a[y-1]=1
  elif a[x-1]==1:
    a[y-1]=1
  b[x-1]-=1
  b[y-1]+=1
    
print(sum(a))

Solution (Python):
n,m=list(map(int,input().split()))
B=[1]*n
R=[False]*n
R[0]=True

for i in range(m):
  x,y=list(map(int,input().split()))
  B[y-1]+=1
  B[x-1]-=1

  if R[x-1]==True:
    if B[x-1]==0:
      R[x-1]=False
      R[y-1]=True
    else:
      R[y-1]=True      

print(R.count(True))

Solution (Python):
N,M = map(int, input().split())

dp = [1] * N
red = [False] * N
red[0] = True
for i in range(M):
    xi,yi = map(int, input().split())
    xi-=1
    yi-=1
    dp[yi] += 1
    red[yi] = red[yi] or red[xi]
    dp[xi] -= 1
    if dp[xi] == 0:
        red[xi] = False

ans = sum(red)
print(ans)

Solution (Python):
N, M = map(int, input().split())

cnt = [1 for _ in range(N)]
red = [True] + [False for _ in range(N - 1)]

for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    cnt[x] -= 1
    cnt[y] += 1
    if red[x]:
        red[y] = True
    if cnt[x] == 0:
        red[x] = False

print(sum(red))

Solution (Python):
n, m = map(int, input().split())
move = [tuple(map(int, input().split())) for i in range(m)]

ball = [1] * (n+1)
red = [False] * (n+1)
red[1] = True

for x, y in move:
  ball[x] -= 1
  ball[y] += 1
  if red[x]: red[y] = True
  if ball[x] == 0: red[x] = False

ans = red.count(True)
print(ans)

Solution (Python):
n,m = [int(x) for x in input().split()]
xy = []
for _ in range(m):
    tmp = [int(x)-1 for x in input().split()]
    xy.append(tmp)

num = [1 for _ in range(n)]
red = [False for _ in range(n)]
red[0] = True

for i in range(m):
    if red[xy[i][0]]:
        red[xy[i][1]] = True
    num[xy[i][0]] -= 1
    num[xy[i][1]] += 1
    if num[xy[i][0]] == 0:
        red[xy[i][0]] = False

print(sum([1 for x in red if x == True]))

Solution (Python):


from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
xy = [list(map(int, stdin.readline().rstrip().split())) for i in range(m)]

num = [1] * n
red = [False] * n
red[0] = True
for i in range(m):
    if red[xy[i][0] - 1]:
        red[xy[i][1] - 1] = True
    num[xy[i][0] - 1] = num[xy[i][0] - 1] - 1
    num[xy[i][1] - 1] = num[xy[i][1] - 1] + 1
    if num[xy[i][0] - 1] == 0:
        red[xy[i][0] - 1] = False

print(sum(red))

Solution (Python):
N, M = list(map(int, input().split()))
boxes = [1] * N
boxes_status = [False] * N
boxes_status[0] = True

for i in range(M):
  x, y = list(map(int, input().split()))
  x -= 1
  y -= 1
  if boxes_status[x]:
    if boxes[x] == 1:
      boxes_status[x] = False
    boxes_status[y] = True
  boxes[x] -= 1
  boxes[y] += 1

print(boxes_status.count(True))

Solution (Python):
N, M = map(int, input().split())

num = [1 for _ in range(N)]
red = [False for _ in range(N)]
red[0] = True

for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    if red[x]:
        red[y] = True

    num[x] -= 1
    num[y] += 1

    if num[x] == 0:
        red[x] = False

print(sum(red))

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, M = map(int, input().split())
    box = [0] + [1 for _ in range(N)]
    red = [0, 1] + [0 for _ in range(N - 1)]
    for _ in range(M):
        x, y = map(int, input().split())
        if red[x]:
            red[y] = 1
        box[x] -= 1
        box[y] += 1
        if not box[x]:
            red[x] = 0
    answer = sum(red)
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
N, M = map(int, input().split())
X, Y = [], []

for _ in range(M):
    xi, yi = map(int, input().split())
    X.append(xi)
    Y.append(yi)

possible = [True] + [False] * (N - 1)
count = [1] * N

for i in range(M):
    xi, yi = X[i] - 1, Y[i] - 1

    
    if possible[xi]:
        possible[yi] = True
    
    count[xi] -= 1
    count[yi] += 1
    
    if count[xi] == 0:
        possible[xi] = False

count = 0
for f in possible:
    if f:
        count += 1
print(count)

Solution (Python):
def main():
    N, M = map(int, input().split())
    l = []
    for i in range(M):
        l.append(list(map(int, input().split())))
    s = [1 for i in range(N)]
    r = [0 for i in range(N)]
    r[0] = 1
    for i in range(M):
        x = l[i][0] - 1
        y = l[i][1] - 1
        if r[x] == 1:
            if s[x] == 1:
                r[x] = 0
            r[y] = 1
        s[x] -= 1
        s[y] += 1
    print(sum(r))

main()

Solution (Python):
N,M=map(int,input().split())
x=[0]*M
y=[0]*M

for i in range(M):
  x[i],y[i] = map(int,input().split())
  
pos = [1]+[0]*(N-1)
num = [1]*N

for i in range(M):
  if pos[x[i]-1]==1:
    if num[x[i]-1]==1:
      pos[x[i]-1]=0
      pos[y[i]-1]=1
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
    else:
      pos[y[i]-1]=1
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
  else:
      num[x[i]-1] -= 1
      num[y[i]-1] += 1
  
  
  
print(sum(pos))

Solution (Python):
N, M = map(int, input().split())
sift = [list(map(int, input().split())) for _ in range(M)]
ball = [0] * N
ball[0] = 1
num_ball = [1] * N
for i in range(M):
    
    a, b = sift[i]
    a -= 1
    b -= 1
    if ball[a] == 1:
        if num_ball[a] > 1:
            ball[b] = 1
            num_ball[a] -= 1
            num_ball[b] += 1
        else:
            ball[b] = 1
            ball[a] = 0
            num_ball[b] += 1
            num_ball[a] -= 1
    else:
        num_ball[a] -= 1
        num_ball[b] += 1
print(sum(ball))

Solution (Python):
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
xy = [[int(x) for x in input().split()] for _ in range(m)]

status = [[0, 1] for _ in range(n + 1)]
status[1] = [1, 1] 

for i in range(m):
    x, y = xy[i]
    if status[x][0] == 1:
        if status[x][1] > 1:
            status[x][1] -= 1
        else:
            status[x] = [0, 0]
        status[y][0] = 1
        status[y][1] += 1
    else:
        status[x][1] -= 1
        status[y][1] += 1

ans = 0

for i in status[1:]:
    if i[0] == 1:
        ans += 1

print(ans)

Solution (Python):
N, M = map(int, input().split())
X, Y = [], []

for _ in range(M):
    x, y = map(int, input().split())
    X.append(x - 1)
    Y.append(y - 1)

red = [0] * N
red[0] = 1
ball = [1] * N

for x, y in zip(X, Y):
    if red[x] == 1 and ball[x] != 0:
        red[y] = 1
        if ball[x] == 1:
            red[x] = 0
        ball[x] -= 1
        ball[y] += 1
    elif ball[x] != 0:
        ball[x] -= 1
        ball[y] += 1

print(sum(red))

Solution (Python):
n,m=map(int,input().split())
xy = [ list(map(int,input().split())) for _ in range(m) ]

ans=0
jagh=[0]*n
jagh[0]=1
now=[1]*n
for i in range(m):
    if jagh[xy[i][0]-1]==1:
        jagh[xy[i][1]-1]=1
        now[xy[i][0]-1]-=1
        if now[xy[i][0]-1]==0:
            jagh[xy[i][0]-1]=0
        now[xy[i][1]-1]+=1
    else:
        now[xy[i][0]-1]-=1
        if now[xy[i][0]-1]==0:
            jagh[xy[i][0]-1]=0
        now[xy[i][1]-1]+=1


for i in range(n):
    if jagh[i]==1 and 0<now[i]:
        ans+=1
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
balls = [[1, 0] for _ in range(N)]  
balls[0] = [0, 1]

for _ in range(M):
	x, y = MAP()

	w_x, r_x = balls[x-1]
	w_y, r_y = balls[y-1]
	
	if w_x >= 1 and r_x >= 1:
		balls[x-1][0] -= 1
		balls[y-1][1] += 1
	elif w_x == 0:
		balls[x-1][1] -= 1
		balls[y-1][1] += 1
	else:
		balls[x-1][0] -= 1
		balls[y-1][0] += 1

ans = 0
for i in range(N):
	if balls[i][1]:
		ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
X, Y = [0]*M, [0]*M
for i in range(M):
  X[i], Y[i] = map(int,input().split())
status = [False]*N; status[0] = True;
ball = [1]*N

for i in range(M):
  ball[X[i]-1] -= 1
  ball[Y[i]-1] += 1
  if status[X[i]-1] == True:
    status[Y[i]-1] = True
    if ball[X[i]-1] == 0:
      status[X[i]-1] = False
      
print(sum(status))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n, m = LI()
    ok = [1] * n
    ans = [0] * n
    ans[0] = 1
    for _ in range(m):
        x, y = LI_()
        ok[x] -= 1
        ok[y] += 1
        if ans[x]:
            ans[y] = 1
        if ok[x] == 0:
            ans[x] = 0
    print(sum(ans))
    return



if __name__ == '__main__':
    solve()

Solution (Python):
N, M = map(int, input().split())
colors = ['R'] + ['W'] * (N-1)
counts = [1]*N

def receive(color, id):
    counts[id] += 1
    if colors[id] == 'E':
        colors[id] = color
    elif color != colors[id]:
        colors[id] = 'M'

def send(id):
    color = colors[id]
    counts[id] -= 1
    if counts[id] == 0:
        colors[id] = 'E'
    return color

for i in range(M):
    x, y = map(int, input().split())
    c = send(x-1)
    receive(c, y-1)

print(sum([1 for c in colors if c == 'R' or c == 'M']))

Solution (Python):
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)


inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


def main():
    N, M = map(int, input().split())
    xy = []
    for _ in range(M):
        xy.append(list(map(int, input().split())))
    prob = [False] * N
    prob[0] = True
    ball = [1] * N
    for x, y in xy:
        ball[x-1] = ball[x-1] - 1
        ball[y-1] = ball[y-1] + 1
        if ball[x-1] < 1 and prob[x-1]:
            prob[x-1] = False
            prob[y-1] = True
        elif ball[x-1] >= 1 and prob[x-1]:
            prob[y-1] = True
    print(prob.count(True))


if __name__ == '__main__':
    main()

Solution (Python):
N,M  = map(int, input().split())
balls = [1]*(N+1)
reds = [False]*(N+1)
reds[0] = True
for i in range(M):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    balls[x] -= 1
    balls[y] += 1
    if reds[x]:
        reds[y] = True
    if balls[x] == 0:
        reds[x] = False

print(sum(reds))

Solution (Python):
N,M=map(int,input().split())
op=[list(map(int,input().split())) for _ in range(M)]
susflag=[0]*N
susflag[0]=1
num=[1]*N
fr=0
to=0

for i in range(M):
    fr=op[i][0]-1
    to=op[i][1]-1
    num[fr]=num[fr]-1
    num[to]=num[to]+1
    if susflag[fr]==1:
        susflag[to]=1
    if num[fr]==0:
        susflag[fr]=0
    
print(sum(susflag))

Solution (Python):
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
balls = [1 for _ in range(N + 1)]
ans[1] = True
for i in range(M):
  q = list(map(int,input().rstrip().split(" ")))
  if ans[q[0]] == True:
    ans[q[1]] = True
  balls[q[0]] -= 1
  if balls[q[0]] == 0: ans[q[0]] = False
  balls[q[1]] += 1
ansi = 0
for i in range(N + 1):
  if ans[i]: ansi += 1
print(ansi)

Solution (Python):
n, m = map(int, input().split())
xy = []
for i in range(m):
    xy.append(list(map(int, input().split())))

x = 0
y = 1


for _xy in xy:
    _xy[x] -= 1
    _xy[y] -= 1

red = [False] * n
red[0] = True
ballCnt = [1] * n

for i in range(m):
    
    ballCnt[xy[i][x]] -= 1
    ballCnt[xy[i][y]] += 1

    if red[xy[i][x]]:
        red[xy[i][y]] = True

    if ballCnt[xy[i][x]] == 0:
        red[xy[i][x]] = False



ans = 0
for r in red:
    if r:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ans = [1] * n
check = [False] * n
check[0] = True
for i in range(m):
  x, y = map(int, input().split())
  ans[x - 1] -= 1
  ans[y - 1] += 1
  if check[x - 1]:
    check[y - 1] = True
    if ans[x - 1] == 0:
      check[x - 1] = False
print(sum(check))

Solution (Python):
N, M = map(int, input().split())
box_num = [1]*N
box_color = [0]*N
box_color[0] = 1   

for _ in range(M):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    box_num[x] -= 1
    box_num[y] += 1

    if box_num[y] != 1:
        if box_color[x]==box_color[y]:
            pass
        else:
            box_color[y] = 2
    else:
        box_color[y] = box_color[x]

ans = 0
for n, c in zip(box_num, box_color):
    if n>0:
        if c != 0:
            ans += 1

print(ans)

Solution (Python):
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    poss  = [False]*n
    poss[0] = True
    cnts = [int() + 1]*n
    
    for i in range(m):
        
        xi,yi = map(int, input().split())
        if poss[xi-1]:
            if cnts[xi-1] == 1:
                poss[xi-1] = False
            poss[yi-1] = True

        cnts[xi-1] -= 1
        cnts[yi-1] += 1

        
    
    print(sum(poss))
    return

if __name__ == '__main__':
    main()

Solution (Python):
n, m = list(map(int, input().split()))

moves = [list(map(int, input().split())) for i in range(m)]

possibilities = [False] * n
possibilities[0] = True
nums = [1] * n

for i in range(m):
    x = moves[i][0] - 1
    y = moves[i][1] - 1

    if possibilities[x]:
        possibilities[y] = True

    nums[x] -= 1
    nums[y] += 1
    if nums[x] == 0:
        possibilities[x] = False

print(sum(possibilities))

Solution (Python):
n, m = list(map(int, input().split()))

moves = [list(map(int, input().split())) for i in range(m)]

possibilities = [False] * n
possibilities[0] = True
nums = [1] * n

for i in range(m):
    x = moves[i][0] - 1
    y = moves[i][1] - 1

    if possibilities[x]:
        possibilities[y] = True

    nums[x] -= 1
    nums[y] += 1
    if nums[x] == 0:
        possibilities[x] = False

ans = 0
for j in range(n):
    if possibilities[j] and (nums[j] > 0):
        ans += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
A = [0 for i in range(N)]
B = [1 for i in range(N)]
A[0] = 1
for i in range(M):
  a, b = map(int, input().split())
  B[a-1] -= 1
  B[b-1] += 1
  if A[a-1] == 1:
    A[b-1] = 1
  if B[a-1] == 0:
    A[a-1] = 0
print(sum(A))

Solution (Python):
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]

ans = [0 for i in range(n)]
balls = [1 for i in range(n)]
ans[0] = 1

for x, y in xy:
    x -= 1
    y -= 1
    if ans[x] == 1 and balls[x] > 0:
        ans[y] = 1
    if balls[x] > 0:
        balls[x] -= 1
        balls[y] += 1
        if balls[x] == 0:
            ans[x] = 0

print(sum(ans))

Solution (Python):
def main():
    boxes, operation_num = map(int, input().split())
    operation = []
    for _ in range(operation_num):
        operation.append(list(map(int, input().split())))
    can_exist_red = [False for _ in range(boxes)]
    ball = [1 for _ in range(boxes)]
    can_exist_red[0] = True
    for op_from, op_to in operation:
        ball[op_to - 1] += 1
        ball[op_from - 1] -= 1
        if can_exist_red[op_from - 1]:
            can_exist_red[op_to - 1] = True
            if ball[op_from - 1] == 0:
                can_exist_red[op_from - 1] = False
    answer = 0
    for c in can_exist_red:
        if c:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, M = map(int, input().split())
    ball = [1] * N
    red = [False] * N
    red[0] = True
    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        ball[x] -= 1
        ball[y] += 1
        if red[x]:
            red[y] = True
        if ball[x] == 0:
            red[x] = False

    ans = 0
    for i in range(N):
        if red[i]:
            ans += 1

    print(ans)




if __name__ == "__main__":
    main()

Solution (Python):
N,M=map(int,input().split())
box=[1]*N
P=[1]+[0]*(N-1)
for i in range(M):
  x,y=map(int,input().split())
  x,y=x-1,y-1
  box[x]-=1
  box[y]+=1
  if P[x]==1:
    P[y]=1
    if box[x]==0:
      P[x]=0
print(sum(P))

Solution (Python):
N,M = list(map(int,input().split()))
d = {i+1:1 for i in range(N)}
isRed = {i+1:False for i in range(N)}

isRed[1] = True
for m in range(M):
  x,y = list(map(int,input().split()))
  d[x] -= 1
  d[y] += 1
  if isRed[x]:
    isRed[y] = True
  if d[x] == 0:
    isRed[x] = False
print(sum(isRed.values()))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
ball = defaultdict(int)
count = defaultdict(int)
ball[1] = 1
for i in range(1,n+1):
    count[i] = 1

for _ in range(m):
    x, y = LI()
    if ball[x] and count[x] > 1:
        ball[y] = 1
        count[x] -= 1
        count[y] += 1
    elif ball[x] and count[x] == 1:
        ball[x] = 0
        ball[y] = 1
        count[x] = 0
        count[y] += 1
    elif not ball[x]:
        count[x] -= 1
        count[y] += 1

ans = 0
for i in range(1,n+1):
    if ball[i]:
        ans += 1
print(ans)

Solution (Python):
N,M = map(int, input().split())

red = [0]*(N+1)
red[1] = 1
ball = [1]*(N+1)
for _ in range(M):
  x,y = map(int, input().split())
  if ball[x] ==1 and red[x] == 1:
    red[x] = 0
    red[y] = 1
  elif red[x] == 1:
    red[y] = 1
  ball[x] -= 1
  ball[y] += 1
  
print(sum(red))

Solution (Python):
N, M = map(int, input().split())
num = [1]*(N+1)
red = [0]*(N+1)
red[1] = 1

for _ in range(1,M+1):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = 1   
    num[x] = num[x]-1
    num[y] = num[y]+1
    if num[x]==0:
        red[x] = 0

ans = 0
for i in range(1,N+1):
    if red[i] == 1:
        ans+=1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())

    vol = [1 for i in range(N)]
    prob = [False for _ in range(N)]
    prob[0] = True
    
    for _ in range(M):
        a,b = map(int,input().split())
        if prob[a-1]:
            prob[b-1] = True
        vol[a-1] -= 1
        vol[b-1] += 1
        if vol[a-1] == 0:
            prob[a-1] = False

    print(prob.count(True))

if __name__ == "__main__":
    main()

Solution (Python):
N, M = map(int,input().split())

cnt = [1 for i in range(N+1)]
flag = [0 for i in range(N+1)]
flag[1] = 1

for _ in range(M):
    x, y = map(int,input().split())
    if flag[x]:
        flag[y] = 1
    if cnt[x] == 1 and flag[x]:
        flag[x] = 0
    cnt[x] -= 1
    cnt[y] += 1

print(sum(flag))

Solution (Python):
n, m = map(int, input().split())
box = [[0, 1] for _ in range(n+1)]
box[0][1] = 0
box[1][0] = 1
for i in range(m):
  x, y = map(int, input().split())
  if box[x][0]:
    box[y][0] = 1
  box[x][1] -= 1
  box[y][1] += 1
  if box[x][1] == 0:
    box[x][0] = 0
print(sum(box[x][0] for x in range(1,n+1)))

Solution (Python):
N,M = map(int, input().split())

ans = set([0])
cnt = [1] * N
for _ in range(M):
    x,y = [int(i) - 1 for i in input().split()]
    cnt[x] -= 1
    cnt[y] += 1

    if x in ans:
        if cnt[x] == 0:
            ans.remove(x)
        ans.add(y)

print(len(ans))

Solution (Python):
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

cnt = [1] * n
red = [0] * n
red[0] = 1

for x, y in xy:
    x -= 1
    y -= 1
    if red[x]:
        if cnt[x] == 1:
            red[x] = 0
        red[y] = 1

    cnt[x] -= 1
    cnt[y] += 1

ans = sum(red)
print(ans)

Solution (Python):
n,m=map(int,input().split())
ans=[0 for _ in range(n)]
ans[0]=1
li=[1 for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    if ans[x-1]==1:
        ans[y-1]=1
    if li[x-1]==1:
        ans[x-1]=0
    li[x-1]-=1
    li[y-1]+=1
  
cnt=0
for i in range(n):
    if li[i]!=0 and ans[i]!=0:
        cnt+=1
print(cnt)

Solution (Python):
def examA():
    a, b = LI()
    if b<a:
        a,b = b,a
    if a<=0 and 0<=b:
        print("Zero")
    elif 0<a:
        print("Positive")
    else:
        judge = b-a+1
        if judge%2==0:
            print("Positive")
        else:
            print("Negative")
    return

def examB():
    N, M = LI()
    flag_R = [False]*N
    cnt = [1]*N
    flag_R[0] = True
    for _ in range(M):
        x, y = LI()
        x -= 1; y -= 1
        if flag_R[x]:
            flag_R[y] = True
        cnt[y] += 1
        cnt[x] -= 1
        if cnt[x]==0:
            flag_R[x] = False
    ans = sum(flag_R)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Solution (Python):
N, M = map(int, input().split(' '))
nums = [1 for _ in range(N)]
has_balls = [False for _ in range(N)]
has_balls[0] = True

for _ in range(M):
    x, y = map(int, input().split(' '))
    x -= 1
    y -= 1

    if has_balls[x]:
        has_balls[y] = True

    nums[y] += 1
    nums[x] -= 1
    if not nums[x]:
        has_balls[x] = False



ret = 0
for h in has_balls:
    if h:
        ret += 1

print(ret)

Solution (Python):

n,m = map(int,input().split())
cnt = [1]*n
visit = [0]*n
visit[0] = 1
for i in range(m):
    x,y = map(int,input().split())
    if visit[x-1] > 0:
        if cnt[x-1] == 1:
            visit[x-1] = 0
        visit[y-1] =1
    cnt[x-1] -=1
    cnt[y-1] += 1
print(sum(1 for i in visit if i > 0))

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, m = list(map(int,ipti().split()))

    ball = [1] * n
    ball[0] = -1

    for i in range(m):
        x, y = list(map(int,ipti().split()))
        x ,y = x-1, y-1

        if ball[x] < 0:
            ball[x] += 1
            if ball[y] >= 0:
                ball[y] += 1
                ball[y] *= -1
            else:
                ball[y] -= 1
        else:
            ball[x] -= 1
            if ball[y] >= 0:
                ball[y] += 1
            else:
                ball[y] -= 1

    ans = 0

    for i in range(n):
        if ball[i] < 0:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
box_l=[1]*n
red_l=[0]*n
red_l[0]=1

for i in range(m):
	x,y=map(int,input().split())
	x-=1
	y-=1
	if red_l[x]==1:
		red_l[y]=1
		if box_l[x]==1:
			red_l[x]=0
	box_l[x] -= 1
	box_l[y] += 1
print(sum(red_l))

Solution (Python):
n, m = map(int, input().split())
flag = [False] * n
quan = [1] * n
flag[0] = True
for i in range(m):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    if flag[x]:
        flag[y] = True
    quan[x] -= 1
    quan[y] += 1
    if quan[x] == 0:
        flag[x] = False

print(len(list(filter(lambda x: x == True, flag))))

Solution (Python):
n, m = map(int, input().split())


candidate = set([1])
ball = [1 for i in range(n+1)]
for i in range(m):
    x, y = map(int, input().split())
    if x in candidate:
        candidate.add(y)
    else:
        if ball[y] == 0 and y in candidate:
            candidate.remove(y)
    ball[x] -= 1
    ball[y] += 1
for i in range(1,n+1):
    if ball[i] == 0 and i in candidate:
        candidate.remove(i)
print(len(candidate))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m = MAP()
red = [False for _ in range(n)]
bal = [1 for _ in range(n)]
red[0] = 1
for i in range(m):
    x, y = MAP()
    if red[x - 1]:
        red[y - 1] = True
        if bal[x - 1] == 1:
            red[x - 1] = False
    bal[x - 1] -= 1
    bal[y - 1] += 1
print(sum(red))

Solution (Python):
N,M=map(int,input().split())
red=[1]+[0 for _ in range(1,N)]
num=[1]*N

for _ in range(M):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if red[x]>0:
        if num[x]==1:
            red[y]=red[x]
            red[x]=0
        else:
            red[x]=1
            red[y]=1
    num[x]-=1
    num[y]+=1

print(len([True for r in red if r>0]))