#include<bits/stdc++.h>
using namespace std;
int n,m,f[500005],a[500005],ans=0,xx,yy;
int find(int x){
if(f[x] == x) return x;
return f[x] = find(f[x]);
}
int main(){
freopen("religion.in","r",stdin);
freopen("religion.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++) f[i] = i;
for(int i = 1; i <= m; i++){
scanf("%d%d",&xx,&yy);
int fx=find(xx),fy=find(yy);
if (fx!=fy) f[fx]=fy;
}
for(int i = 1; i <= n; i++){
int w = find(i);
if(!a[w]){
ans++;
a[w]++;
}
}
cout << ans;
return 0;
}