from collections import deque
import sys
# 입력
n, m = map(int,sys.stdin.readline().split())
graph = dict()
visited = [False] * (n+1)
count = 0
for _ in range(m):
u, v = map(int,sys.stdin.readline().split())
if u in graph:
graph[u].append(v)
else:
graph[u] = [v]
if v in graph:
graph[v].append(u)
else:
graph[v] = [u]
# 처리
def dfs(graph, queue):
while queue:
c = int(queue.pop())
if visited[c] == False:
visited[c] = True
if c in graph:
queue += deque(graph[c])
for i in range(1, n+1):
if visited[i] == False:
dfs(graph, deque([i]))
count += 1
print(count)