N,M = map(int,input().split()) """ parent = list(range(N+1)) import sys sys.setrecursionlimit(10 ** 8) def find(i): if parent[i] == i:return i parent[i] = find(parent[i]) return parent[i] def unite(i,j): I = find(i) J = find(j) if I == J:return False parent[I] = J parent[i] = J return True for _ in range(M): a,b = map(int,input().split()) unite(a,b) ans = 0 """ G = [0] * (N+1) rG = [0] * (N + 1) for _ in range(M): a,b = map(int,input().split()) G[a] += 1 rG[b] += 1 count1 count2 for i in range(1,N+1): if G[i] == 0: count1 += 1 if rG[i] == 0: count2 += 1 print(max(count1,count2))