#include <fstream>
#include <vector>
#define pb push_back
std::ifstream in("dfs.in");
std::ofstream out("dfs.out");
int n,m;
std::vector<std::vector<int>>nod;
std::vector<bool>vis;
void dfs(int idx) {
if(vis[idx]) {return;}
vis[idx] = true;
for(int i = 0 ; i < nod[idx].size() ; i ++ ) {
dfs(nod[idx][i]);
}
}
int main(void) {
in >> n >> m;
nod.resize(n+1);
int a,b,ans = 0;
while(in >> a >> b) {
nod[a].pb(b);
nod[b].pb(a);
}
vis.resize(n+1);
for(int i = 1 ; i < nod.size() ; i ++ ) {
if(!vis[i]) {
dfs(i);
ans++;
}
}
out << ans;
return 0;
}