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





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



for _ in range(m):

    x, y = [int(x) - 1 for x in 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)))
n, m = list(map(int, input().split()))



num = [1]*n

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



for _ in range(m):

    x, y = [int(x)-1 for x in input().split()]

    num[x] -= 1

    num[y] += 1



    if red[x]:

        red[y] = 1

    if num[x] == 0:

        red[x] = 0



print((sum(red)))
n, m = list(map(int, input().split()))
A = [[1, 1]] + [[0, 1] for _ in range(n - 1)]
for _ in range(m):
    x, y = [int(x) - 1 for x in 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)))

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

-A = [[1, 1]] + [[0, 1] for _ in range(n - 1)] +num = [1] * n +red = [1] + [0] * (n - 1) -    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))) +    num[x] -= 1 +    num[y] += 1 +    if red[x]: +        red[y] = 1 +    if num[x] == 0: +        red[x] = 0 +print((sum(red)))