n, m = map(int, input().split()) in_ = [0] * n out_ = [0] * n for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 in_[v] += 1 out_[u] += 1 tot = 0 for i, o in zip(in_, out_): tot += max(0, i - o) print(max(0, tot - 1))