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

XY = [tuple(map(int,input().split())) for i in range(M)]



rs = [0] * N

rs[0] = 1

cs = [1] * N

for x,y in XY:

    x,y = x-1,y-1

    if rs[x]:

        if cs[x]==1:

            rs[x] = 0

        rs[y] = 1

    cs[x] -= 1

    cs[y] += 1

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

XY = [tuple(map(int,input().split())) for i in range(M)]



may_red = [0] * N

may_red[0] = 1

balls = [1] * N



for x,y in XY:

    x,y = x-1,y-1

    if may_red[x]:

        may_red[y] = 1

        if balls[x] == 1:

            may_red[x] = 0

    balls[x] -= 1

    balls[y] += 1

print((sum(may_red)))
N, M = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(M)]
rs = [0] * N
rs[0] = 1
cs = [1] * N
for x, y in XY:
    x, y = x - 1, y - 1
    if rs[x]:
        if cs[x] == 1:
            rs[x] = 0
        rs[y] = 1
    cs[x] -= 1
    cs[y] += 1
print((sum(rs)))

N, M = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for i in range(M)]
may_red = [0] * N
may_red[0] = 1
balls = [1] * N
for x, y in XY:
    x, y = x - 1, y - 1
    if may_red[x]:
        may_red[y] = 1
        if balls[x] == 1:
            may_red[x] = 0
    balls[x] -= 1
    balls[y] += 1
print((sum(may_red)))

-rs = [0] * N -rs[0] = 1 -cs = [1] * N +may_red = [0] * N +may_red[0] = 1 +balls = [1] * N -    if rs[x]: -        if cs[x] == 1: -            rs[x] = 0 -        rs[y] = 1 -    cs[x] -= 1 -    cs[y] += 1 -print((sum(rs))) +    if may_red[x]: +        may_red[y] = 1 +        if balls[x] == 1: +            may_red[x] = 0 +    balls[x] -= 1 +    balls[y] += 1 +print((sum(may_red)))