#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
ifstream f("dfs.in");
ofstream g("dfs.out");
int main()
{
int n,m;
f>>n>>m;
vector<vector<int>>a(n+1);
vector<bool> visited(n+1, false);
for(int i=1;i<=m;i++){
int x,y;
f>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
int componente = 0;
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
componente++;
stack<int> stack;
stack.push(i);
visited[i] = true;
while (!stack.empty()) {
int u = stack.top();
stack.pop();
for (int v : a[u]) {
if (!visited[v]) {
visited[v] = true;
stack.push(v);
}
}
}
}
}
g << componente;
return 0;
}