n, m = map(int,input().split()) din = [0] * n dout = [0] * n for i in range(m): u, v = map(int,input().split()) u -= 1 v -= 1 din[v] += 1 dout[u] += 1 nouse = 0 tmp = [] for i in range(n): tmp.append(dout[i] - din[i]) if dout[i] == din[i] == 0: nouse += 1 tmp.sort() # euler graph ans = 0 for i in range(n): if tmp[i] > 0: ans += tmp[i] #ans = min(ans, tar) if ans == 0: print(max(ans, nouse + 1)) exit() # jun euler graph ans -= 1 ans = max(ans, nouse + 1) print(ans)