import sys
input = sys.stdin.readline
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
visit = [False] * (n + 1)
def dfs(x):
visit[x] = True
for i in graph[x]:
if not visit[i]:
dfs(i)
ans = 0
for i in range(1, n + 1):
if not visit[i]:
dfs(i)
ans += 1
print(ans)