from collections import deque
from platform import node


N, M = map(int, input().split())

G: list = [[] for _ in range(N)]
nodes: set = set()

for i in range(N):
    nodes.add(i)
for j in range(M):
    u, v = map(int, input().split())
    G[u - 1].append(v - 1)
    G[v - 1].append(u - 1)


cnt = 0
while nodes:
    q: deque = deque()
    q.append(nodes.pop())
    while q:
        n = q.popleft()
        for nx in G[n]:
            if nx in nodes:
                nodes.remove(nx)
                q.append(nx)
    cnt += 1


print(cnt)
