import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 class UnionFind: def __init__(self, n): self.table = [-1]*n self.mem = [[u] for u in range(n)] self.cnt = n def root(self, u): stack = [] while self.table[u] >= 0: stack.append(u) u = self.table[u] for v in stack: self.table[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False su = -self.table[u] sv = -self.table[v] if su < sv: u, v = v, u self.table[u] = -su-sv self.table[v] = u self.mem[u] += self.mem[v] self.mem[v].clear() self.cnt -= 1 return True def member(self,u): return self.mem[self.root(u)] # グループの要素数 def size(self, u): return -self.table[self.root(u)] n,m=LI() uf=UnionFind(n) deg=[0]*n for _ in range(m): u,v=LI1() deg[u]-=1 deg[v]+=1 uf.merge(u,v) s=sum(d for d in deg if d>0) ans=-1 if uf.cnt>1: for uu in uf.mem: if len(uu)<2:continue ans+=1 print(max(0,s-1,ans))