import sys sys.setrecursionlimit(200050) def root(x): if P[x] < 0: return x else: P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x, y): x = root(x) y = root(y) if x == y: P[x] -= 1 return if x > y: x,y = y,x P[x] = min(P[x], P[y]) - 1 P[y] = x def same(x, y): return root(x) == root(y) def size(x): x = root(x) return -P[x] N, M = map(int, input().split()) UV = [list(map(int, input().split())) for _ in range(M)] P = [-1] * (N + 1) cnt = 0 for u, v in reversed(UV): unite(u, v) print(- P[1] - 1)