N, M = map(int, input().split()) deg = [0 for _ in range(N)] indeg = [0 for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u-=1 v-=1 deg[u] += 1 indeg[v] += 1 sa = [0 for _ in range(N)] plus = 0 minus = 0 for i in range(N): sa[i] = indeg[i]-deg[i] if sa[i]>0: plus += sa[i] elif sa[i]<0: minus += -sa[i] if plus==0: print(0) else: print(plus-1)