#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<int> viz;
void dfs(int start){
viz[start] = 1;
for(int i = 0; i < adj[start].size(); i++){
int nextNode = adj[start][i];
if (!viz[nextNode]){
dfs(nextNode);
}
}
}
int main(){
ifstream fin("dfs.in");
ofstream fout("dfs.out");
int n, m, compConexe = 0;
fin >> n >> m;
adj.resize(n+5);
viz.resize(n+5);
for(int i = 0; i < m; i++){
int x, y;
fin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
for(int i = 1; i <= n; i++){
if (!viz[i]){
dfs(i);
compConexe++;
}
}
fout << compConexe;
}