N,M = map(int,input().split()) Gnum = [0] * (N + 1) for _ in range(M): u,v = map(int,input().split()) Gnum[u] -= 1 Gnum[v] += 1 a = 0 b = 0 p = 0 q = 0 for i in range(1,N + 1): if Gnum[i] == 1: if a == 0:a = 1 else: p += 1 elif Gnum[i] == -1: if b == 0:b = 1 else: q += 1 elif Gnum[i] == 0: pass elif Gnum[i] > 0: p += Gnum[i] else: q -= Gnum[i] print(p)