n, m = map(int,input().split())
graph = [[] for _ in range(n + 1)]
# ๋ฌด๋ฐฉํฅ์ฑ์ ๊ฐ์ ์ด ์ฃผ์ด์ง ์ ์์ชฝ์ graph ์ ๋ณด๋ฅผ ์ค์ผํจ
for _ in range(m):
a, b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
# ๊ฐ์ ์ด ์์ผ๋ฉด ์ฐ๊ฒฐ์์๊ฐ ์์ผ๋ 0 ์ถ๋ ฅ
if not m:
print(0)
exit()
visited = []
cnt = 0
def dfs(node):
visited.append(node)
for i in graph[node]:
if i not in visited:
dfs(i)
# ๋ฐฉ๋ฌธ๋์ง ์์ ๋ชจ๋ ๋
ธ๋์ ๋ํด์ dfs ์ํ
for i in range(1, n + 1):
if i not in visited:
dfs(i)
cnt += 1
print(cnt)