#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,res;
int f[50010],mk[50010];
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);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
for (int i=1;i<=50000;i++) f[i]=i;
cin >> n >> m;
for (ll i=1;i<=m;i++) {
int x,y;
cin >> x >> y;
int fx=find(x),fy=find(y);
if (fx==fy) continue;
f[fx]=fy;
}
for (int i=1;i<=n;i++) {
if (mk[find(i)]) continue;
mk[find(i)]=1;
res++;
}
cout << res;
return 0;
}