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):
N,M=map(int,input().split())
red=[2]+[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]))

Solution (Python):
def main():
    n, m = map(int, input().split())
    a = [1]*n
    f = [False]*n
    f[0] = True
    for _ in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if f[x]:
            f[y] = True
        a[y] += 1
        a[x] -= 1
        if a[x] == 0:
            f[x] = False
    ans = 0
    for i in range(n):
        if f[i]:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):



import sys
sys.setrecursionlimit(200000000)






def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    N,M=pin()
    ans=0
    red=[False]*N
    red[0]=True
    balls=[1]*N
    
    for i in range(M):
        x,y=pin()
        x,y=x-1,y-1
        
        if red[x]==True:
            red[y]=True
            if balls[x]==1:
                red[x]=False
        balls[x]-=1
        balls[y]+=1    
    print(sum(red))
    
    
"""


"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

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())
num = [1]*N
red = [False]*N
red[0] = True
for i in range(M):
  x, y = map(int,input().split())
  if red[x-1]:
    red[y-1] = True
  num[x-1] -= 1
  num[y-1] += 1
  if num[x-1] == 0:
    red[x-1] = False
print(red.count(True))

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

num = [1]*n
red = [1] + [0]*(n-1)

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

    if red[x]:
        red[y] = 1
    if num[x] == 0:
        red[x] = 0

print(sum(red))

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


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

for _ in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    A[x][1] -= 1
    A[y][1] += 1
    if A[x][0]:
        A[y][0] = 1

    if A[x][1] == 0:
        A[x][0] = 0

print(sum(a[0] for a in A))

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

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,M=map(int,readline().split())
    x=[0]*M
    y=[0]*M
    for i in range(M):
        a,b=map(int,readline().split())
        x[i]=a
        y[i]=b

    li=[[1,0] for _ in range(N+1)]
    li[1][1]=1
    for i in range(M):
        if li[x[i]][0]>=2 and li[x[i]][1]==1:
            li[y[i]][0]+=1
            li[y[i]][1]=1

            li[x[i]][0]-=1

        elif li[x[i]][0]==1 and li[x[i]][1]==1:
            li[y[i]][0]+=1
            li[y[i]][1]=1

            li[x[i]][0]-=1
            li[x[i]][1]=0

        else:
            li[y[i]][0]+=1

            li[x[i]][0]-=1
            
    count=0
    for i in range(1,N+1):
        if li[i][1]==1: count+=1
    print(count)
if __name__=="__main__":
    main()

Solution (Python):

n,m = [int(i) for i in input().split()]
"""
xs = []
ys = []
for _ in range(m):
    x,y = [int(i) for i in input().split()]
    xs.append(x)
    ys.append(y)
"""

counts = [1] * n
possible = [1] + [0]*(n-1)

for _ in range(m):
    x,y = [int(i) for i in input().split()]
    
    counts[x-1] -= 1
    counts[y-1] += 1
    
    if possible[x-1]==1:
        possible[y-1] = 1
    
    if counts[x-1]==0:
        possible[x-1] = 0
        
cnt = 0
for v in possible:
    if v==1:
        cnt += 1

print(cnt)

Solution (Python):

n,m = [int(i) for i in input().split()]
xs = []
ys = []
for _ in range(m):
    x,y = [int(i) for i in input().split()]
    xs.append(x)
    ys.append(y)
    
counts = [1] * n
possible = [1] + [0]*(n-1)

for i in range(m):
    x = xs[i]
    y = ys[i]
    
    counts[x-1] -= 1
    counts[y-1] += 1
    
    if possible[x-1]==1:
        possible[y-1] = 1
    
    if counts[x-1]==0:
        possible[x-1] = 0
        
cnt = 0
for v in possible:
    if v==1:
        cnt += 1

print(cnt)

Solution (Python):


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

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

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

print(sum(red))

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

Solution (Python):
def solve():
    N, M = map(int, input().split())
    n_ball = [1] * N
    could_exist = [False] * N
    could_exist[0] = True

    for _ in range(M):
        frm, to = map(lambda elem:int(elem)-1, input().split())
        if could_exist[frm] and n_ball[frm] > 0:
            could_exist[to] = True
        if could_exist[frm] and n_ball[frm] == 1:
            could_exist[frm] = False
        n_ball[frm] -= 1
        n_ball[to] += 1
    
    print(sum(could_exist))
    
if __name__ == '__main__':
    solve()

Solution (Python):
def main():
  n, m = input_list()
  box = [False]*n
  box[0] = True
  nums = [1]*n
  for i in range(m):
    x, y = input_list()
    if box[x-1]:
      box[y-1] = True
    nums[x-1] = nums[x-1] - 1
    nums[y-1] = nums[y-1] + 1
    if nums[x-1] == 0:
      box[x-1] = False
  print(box.count(True))
    

def input_list():
  return map(int, input().split())

import math
main()

Solution (Python):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
count=[1]*(n+1)
flag=[False]*(n+1)
flag[1]=True
for a,b in arr:
  count[b]+=1
  count[a]-=1
  if flag[a]==True:
    flag[b]=True
  if count[a]==0:
    flag[a]=False
print(flag.count(True))

Solution (Python):
n,m=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(m)]
count=[1]*(n+1)
s=set()
s.add(1)
for a,b in arr:
  count[b]+=1
  count[a]-=1
  if a in s:
    s.add(b)
  if count[a]==0:
    s.discard(a)
print(len(s))

Solution (Python):
n,m=map(int,input().split())
data=[]
for i in range(m):
    x,y=map(int,input().split())
    data.append((x,y))
ball=[[1,False] for i in range(n)]
ball[0][1]=True

for i in range(m):
    x,y=data[i][0],data[i][1]
    
    if ball[x-1][0]==1:
        
        if ball[x-1][1]==True:
            ball[x-1][0]=0
            ball[y-1][0]+=1
            ball[x-1][1]=False
            ball[y-1][1]=True      
        elif ball[x-1][1]==False:
            ball[x-1][0]=0
            ball[y-1][0]+=1
    elif ball[x-1][0]>=2:
        
        if ball[x-1][1]==True:
            ball[x-1][0]-=1
            ball[y-1][0]+=1
            ball[y-1][1]=True
        elif ball[x-1][1]==False:            
            ball[x-1][0]-=1
            ball[y-1][0]+=1
cnt=0
for i in range(n):
    if ball[i][1]:
        cnt+=1
print(cnt)

Solution (Python):
def main():
    n, m = map(int,input().split())
    x = []
    y = []
    for _ in range(m):
        xx, yy = map(int,input().split())
        x.append(xx-1)
        y.append(yy-1)
    ans = [0] * n
    ans[0] = 1
    red = [0] * n
    red[0] = 1
    num = [1] * n
    for i in range(m):
        if num[x[i]] > 0:
            num[x[i]] -= 1
            num[y[i]] += 1
            if ans[y[i]] == 0 and red[x[i]] == 1:
                ans[y[i]] = 1
                red[y[i]] = 1
            if num[x[i]] == 0 and ans[x[i]] == 1:
                red[x[i]] = 0
                ans[x[i]] = 0
    
    print(sum(ans))

if __name__ == '__main__':
    main()

Solution (Python):
"""考え方
以下の2種類の配列を用意する。（いずれも、サイズは（1,N）)
1.どこに赤い玉がある可能性があるか
2.どこに何個玉があるか
"""

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

for m in range(M):
  x,y = map(int, input().split())
  
  
  if red[x] > 0:
    
    red[y] = 1
    
  
  num[x] -= 1
  num[y] += 1
  
  
  if red[x] > 0:
    if num[x] == 0:
      red[x] = 0
    
ans = len([True for r in red if r > 0])
print(ans)

Solution (Python):
N,M=map(int, input().split())
XY=[tuple(map(int, input().split()))for _ in range(M)]
C=[1]*N
R=[False]*N
R[0]=True
for x,y in XY:
    x-=1
    y-=1
    if R[x]:
        R[y]=True
        if C[x]==1:
            R[x]=False
    C[x]-=1
    C[y]+=1
print(sum(R))

Solution (Python):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l1=[1]*n
l2=[1]+[0]*(n-1)

for x,y in l:
  x-=1
  y-=1

  l1[y]+=1
  if l2[y]==0 and l2[x]==1:
    l2[y]=1

  l1[x]-=1
  if l1[x]==0:
    l2[x]=0

print(l2.count(1))

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

Solution (Python):
n, m = map(int, input().split())
xy = [0] * m
for i in range(m):
    x, y = map(int, input().split())
    xy[i] = (x, y)
red = [0] * n
red[0] = 1
num = [1] * n

for i in range(m):
    moveFrom = xy[i][0] - 1
    moveTo   = xy[i][1] - 1
    if red[moveFrom] == 1 and num[moveFrom] == 1:
        red[moveFrom] = 0
        red[moveTo] = 1
    elif red[moveFrom] == 1:
        red[moveTo] = 1
    num[moveFrom] -= 1
    num[moveTo] += 1

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

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

gray = [False] * n
gray[0] = True
ball = [1] * n

for x, y in xy:
    x -= 1; y -= 1
    ball[x] -= 1
    ball[y] += 1
    if gray[x]:
        gray[y] = True
    if not ball[x]:
        gray[x] = False

print(sum(gray))

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, x: "List[int]", y: "List[int]"):
    c = [1] * (N+1)
    p = [False] * (N+1)
    p[1] = True

    for i in range(M):
        c[y[i]] += 1
        c[x[i]] -= 1

        if p[x[i]] is True:
            p[y[i]] = True
        
        if c[x[i]] == 0:
            p[x[i]] = False

    print([i for i in p if i is True].count(True))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    x = [int()] * (M)  
    y = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, x, y)

if __name__ == '__main__':
    main()

Solution (Python):

N,M=map(int,input().split())
ball = [1 for i in range(N+1)]
ball[0] = 0
red = [0 for i in range(N+1)]
red[1] = 1


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

print(sum(red))

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

red = [0 for i in range(n)]
amount = [1 for i in range(n)]
red[0] = 1
for _ in range(m):
    x,y = map(int,input().split())
    amount[x-1] -= 1
    amount[y-1] += 1
    if red[x-1]:
      red[y-1] = 1
    if amount[x-1] == 0:
      red[x-1] = 0
ans = 0
for r,a in zip(red, amount):
  if r > 0 and a > 0:
    ans += 1



print(ans)

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

box_count=[1]*N
box_color=[1]
buf=[0]*(N-1)
box_color.extend(buf)

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

ans=0
for cnt,color in zip(box_count,box_color):
    if cnt>0 and color==1:
        ans+=1

print(ans)

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

l = [0] * (N + 1)
l[1] = 1
c = [1] * (N + 1)

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

print(sum(l))

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())
    x[i] -= 1
    y[i] -= 1
cnt = [1]*n
flag = [False]*n
flag[0] = True
for i in range(m):
    if flag[x[i]]: 
        flag[y[i]] = True
        if cnt[x[i]] == 1: 
            flag[x[i]] = False
    cnt[x[i]] -= 1
    cnt[y[i]] += 1
    
print(flag.count(True))

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

s = {1}
cnt = [1] * (N + 1)
for i in range(M):
    x, y = map(int, input().split())
    cnt[x] -= 1
    cnt[y] += 1
    if x in s:
        s.add(y)
        if cnt[x] == 0:
            s.discard(x)

print(len(s))

Solution (Python):

N,M=map(int,input().split())
B=[1]*(N+1)
F=[0]*(N+1)
F[1]=1


for i in range(M):
    a,b=map(int,input().split())
    if F[a]==1:
        if B[a]==1:
            F[a]=0
            F[b]=1
        else:
            F[b]=1
        B[a]-=1
        B[b]+=1
    else:
        B[a]-=1
        B[b]+=1


print(F.count(1))

Solution (Python):
n, m = map(int, input().split())
x = []
y = []
for i in range(m):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
num = [1]*n
able = [False]*n
able[0] = True
for i in range(m):
    if able[x[i]-1] == True:
        able[y[i]-1] = True
    num[x[i]-1] -= 1
    num[y[i]-1] += 1
    if num[x[i]-1] == 0:
        able[x[i]-1] = False
print(sum(able))

Solution (Python):


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

Solution (Python):
N, M = map(int, input().split())
boxes = [1] * N
ans = {1}
for i in range(M):
    x, y = map(int, input().split())
    boxes[x - 1] -= 1
    boxes[y - 1] += 1
    if x in ans:
        if boxes[x - 1] == 0:
            ans.remove(x)
        ans.add(y)
print(len(ans))

Solution (Python):
N, M = map(int, input().split())
ball = [1] * N
red = {1}
ans = 0
for _ in range(M):
    x, y = map(int, input().split())
    ball[x - 1] -= 1
    ball[y - 1] += 1
    if x in red:
        red.add(y)
        if ball[x - 1] == 0:
            red.remove(x)
print(len(red))

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

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
ball = [1] * (N+1) 
red = [True if x == 1 else False for x in range(N+1)] 
for _ in range(M):
    x, y = lr()
    if red[x]: red[y] = True
    ball[x] -= 1
    ball[y] += 1
    if ball[x] == 0:
        red[x] = False

answer = sum(red)
print(answer)

Solution (Python):
n, m = map(int, input().split())
l = []
for i in range(m):
    data = list(map(int,input().split()))
    l.append(data)
ball_nums=[1]*n
red_nums=[0]*n
red_nums[0]=1

for i in range(m):
    ball_nums[l[i][0]-1] -= 1
    ball_nums[l[i][1]-1] += 1

    if red_nums[l[i][0]-1]==1:
        red_nums[l[i][1]-1] = 1
        if ball_nums[l[i][0]-1] == 0:
            red_nums[l[i][0]-1] = 0

print(sum(red_nums))

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

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


if __name__ == '__main__':
    main()

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

xx = []
yy = []
for _ in range(m):
    a,b = map(int,input().split())
    xx.append(a-1)
    yy.append(b-1)

for i in range(m):
    x,y = xx[i], yy[i]
    if red_lst[x]==True and red_lst[y]==False:
        red_lst[y]=True
    if lst[x]==1 and red_lst[x]:
        red_lst[x] = False
    lst[x] -= 1
    lst[y] += 1

print(red_lst.count(True))

Solution (Python):
N,M = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(M)]
Q = [1 for i in range(N)]

dp = [0 for i in range(N)] 
dp[0]=1

for i in range(1,M+1):
  x=XY[i-1][0]
  y=XY[i-1][1]

  if dp[x-1]>=1:
    if Q[x-1]==1:
      dp[x-1]=0
    else:
      dp[x-1]=1
    dp[y-1]+=1
  Q[x-1]-=1
  Q[y-1]+=1
  
ans=0
for i in range(N):
  if dp[i]>=1:
    ans+=1
print(ans)

Solution (Python):
N, M = map(int, input().split())
y_if = {1}
num = [1] * N
for i in range(M):
    x, y = map(int, input().split())
    num[x - 1] -= 1
    num[y - 1] += 1
    if x in y_if:
        if num[x - 1] == 0:
            y_if.remove(x)
        y_if.add(y)
print(len(y_if))

Solution (Python):
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]

B=[0]*N
C=[1]*N
B[0]=1
for i in range(M):   
  if (B[(A[i][0]-1)]==1)and(C[(A[i][0]-1)]==1):
    B[(A[i][1]-1)]=1
    B[(A[i][0]-1)]=0
    C[(A[i][0]-1)]=0
    C[(A[i][1]-1)]+=1
  elif (B[(A[i][0]-1)]==1)and(C[(A[i][0]-1)]>1):
    B[(A[i][1]-1)]=1
    C[(A[i][0]-1)]-=1
    C[(A[i][1]-1)]+=1
  else:
    C[(A[i][0]-1)]-=1
    C[(A[i][1]-1)]+=1
    
    
print(sum(B))

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

B = [["w", 1] for _ in range(n)]
B[0][0] = "r"

for i in range(m):
    x, y = XY[i]
    if B[y][1] == 0:
        B[y][0] = B[x][0]
    elif B[x][0] != B[y][0]:
        B[y][0] ="rw"
    B[x][1] -= 1
    B[y][1] += 1
    if B[x][1] == 0:
        B[x][0] = " "


ans = 0
for i in range(n):
    if B[i][1] >= 1 and B[i][0] == "r" or B[i][0] == "rw":
        ans += 1

print(ans)

Solution (Python):
N, M = map(int,input().split())
x,y = [],[]
for _ in range(M):
	tx,ty = map(int, input().split())
	x.append(tx)
	y.append(ty)

flg = [0] * (N+1)
flg[1] = 1
cnt = [1] * (N+1)

for i in range(M):
	cp,np = x[i],y[i]

	if flg[cp] == 1:
		if cnt[cp] == 1:
			flg[cp] = 0
		cnt[cp] -= 1
		cnt[np] += 1
		flg[np] = 1
	else:
		cnt[cp] -= 1
		cnt[np] += 1

print(sum(flg))

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

box = [[0, 0], [1, 1]] + [[1, 0] for i in range(n-1)]

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

ans = 0
for b in box:
    ans += b[1]

print(ans)

Solution (Python):
N,M = map(int,input().split())
red = {}
ball = {}
ans = 1
for i in range(N):
    red[i+1] = 0
    ball[i+1] = 1
red[1] = 1
for i in range(M):
    x,y = map(int,input().split())
    if red[x]:
        if ball[x] == 1:
            red[x] -= 1
            ball[x] -= 1
            if red[y] == 0:
                red[y] += 1
                ball[y] += 1
            else:
                ball[y] += 1
                ans -= 1
        else:
            if red[y] == 0:
                ball[x] -= 1
                red[y] += 1
                ball[y] += 1
                ans += 1
            else:
                ball[x] -= 1
                ball[y] += 1
    else:
        ball[x] -= 1
        ball[y] += 1
            
print(ans)

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m=nm()
rb=[False]*n
rb[0]=True
ball=[1]*n
for i in range(m):
    x,y=nm()
    x-=1
    y-=1
    ball[x]-=1
    ball[y]+=1
    if rb[x]==True:
        rb[y]=True
    if ball[x]==0:
        rb[x]=False
ans=0
for r in rb:
    if r:
        ans+=1
print(ans)

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

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

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

Solution (Python):
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd 
def lcm(a,b):return (a*b) // math.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def comb(l, n): return itertools.combinations(l, n) 
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,M = imn()
xy = [iln() for _ in range(M)]
b = [1] * (N+1)
r_exist = [False] * (N+1)
r_exist[1] = True

for i in range(M):
    s = xy[i][0]
    d = xy[i][1] 
    b[s] -= 1
    b[d] += 1
    if r_exist[s]: r_exist[d] = True
    if b[s] == 0: r_exist[s] = False
ans = 0
for i in range(1, N+1):
    if r_exist[i]: ans += 1
print(ans)

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

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

Solution (Python):
n, m = map(int, input().split())
c = [1] * n
dp = [False] * n
dp[0] = True
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if dp[x]:
        dp[y] = True
        if c[x] == 1:
            dp[x] = False
    c[x] -= 1
    c[y] += 1
print(dp.count(True))

Solution (Python):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
f=[1]*n
ans=[0]*n
ans[0]=1
for i in range(m):
  if ans[l[i][0]-1]==1:
    if f[l[i][0]-1]==1:
      ans[l[i][0]-1]=0
      ans[l[i][1]-1]=1
    else:
      ans[l[i][1]-1]=1
  f[l[i][0]-1]-=1
  f[l[i][1]-1]+=1
print(sum(ans))

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M=two_int()

boxes = [1 for i in range(N)]

dicts={0:1}
for i in range(M):
    A,B=two_int()
    boxes[A-1] -= 1
    boxes[B-1] += 1
    
    if A-1 in dicts:
        dicts[B-1]=1
        
        if boxes[A-1]==0:
            del dicts[A-1]

print(len(dicts))

Solution (Python):

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

ans = 0
for i in range(N):
    if b[i] == True and l[i] > 0:
        ans += 1
print(ans)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
m = map(int,read().split())
XY = 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)

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

def examB():
    N, M = LI()
    boal = [1]*N
    d = defaultdict(bool)
    d[0] = True
    for _ in range(M):
        x,y = LI()
        boal[x-1] -=1
        boal[y-1] +=1
        if d[x-1]:
            d[y-1] = True
        if boal[x-1]==0:
            d[x-1] = False
    ans = sum(d.values())
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
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()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Solution (Python):




n,m = map(int, input().split( ))
red = [0]*(n+1)
cnt = [1]*(n+1)
red[1] = 1
flag = False
for _ in range(m):
    x,y = map(int, input().split( ))
    if red[x] and cnt[x]:
        red[y] = 1
    cnt[x] -= 1
    cnt[y] += 1
    if not cnt[x]:
        red[x] = 0
ans = 0
for i in range(n+1):
    if red[i] and cnt[i]:
        ans += 1

print(ans)

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

Solution (Python):
N,M = map(int,input().split())
XY = [list(map(int,input().split())) for _ in range(M)]

C = [1 for _ in range(N)]
R = [1] + [0 for _ in range(N-1)]
for x,y in XY:
  x -= 1
  y -= 1
  if R[x] == 1:
    R[y] = 1
    if C[x] == 1:
      R[x] = 0
  C[x] -= 1
  C[y] += 1
  
print(sum(R))

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

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

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


status = [1]*N
candidate = [False]*N
candidate[0] = True

for _ in range(M):
    x, y = map(lambda x: int(x)-1, input().split())
    if candidate[x]:
        candidate[y] = True
    status[x] -= 1
    if status[x] == 0:
        candidate[x] = False
    status[y] += 1
print(sum(candidate))

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

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

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

Solution (Python):
N,M = map(int,input().split())
dp = [1 for i in range(N)]
trace = [0 for i in range(N)]
trace[0] = 1
for i in range(M):
    x,y = map(int,input().split())
    dp[y-1] += 1
    dp[x-1] -= 1
    if trace[x-1] >= 1:
        trace[y-1] = trace[x-1]
    if dp[x-1] == 0:
        trace[x-1] = 0

print(len(trace) - trace.count(0))

Solution (Python):
N,M = map(int,input().split())
dp = [1 for i in range(N)]
trace = [0 for i in range(N)]
trace[0] = 1
for i in range(M):
    x,y = map(int,input().split())
    dp[y-1] += 1
    dp[x-1] -= 1
    if trace[x-1] >= 1:
        trace[y-1] = max(trace[y-1]+1,0)
    if dp[x-1] == 0:
        trace[x-1] = 0

print(len(trace) - trace.count(0))