https://www.acmicpc.net/problem/11724
import sys
sys.setrecursionlimit(10000)
def dfs(a):
check[a]=True
for i in arr[a]:
if check[i]==False: dfs(i)
n,m=map(int,input().split())
arr=[[] for _ in range(n+1)]
check=[False]*(n+1)
for _ in range(m):
u,v=map(int,input().split())
arr[u].append(v)
arr[v].append(u)
count=0
for i in range(1,n+1):
if check[i]==False:
dfs(i)
count+=1
print(count)