from collections import defaultdict
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline
n, m = map(int, input().split())
graph = defaultdict(list)
for _ in range(m):
u, v = map(int, input().split())
graph[u].append(v)
graph[v].append(u)
visited = set()
def dfs(v):
visited.add(v)
for i in graph[v]:
if i not in visited:
dfs(i)
ans = 0
for i in range(1, n + 1):
if i not in visited:
dfs(i)
ans += 1
print(ans)
sys.stdin.readline을 쓰는 이유
입력 연산을 빠르게 할 수 있다.