#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50005;
int fa[MAXN];
int find(int x) {
if (fa[x]!=x) {
fa[x]=find(fa[x]);
}
return fa[x];
}
void join(int x, int y) {
int rX = find(x);
int rY = find(y);
if (rX != rY) {
fa[rY] = rX;
}
}
int main() {
freopen("religion.in","r",stdin);
freopen("religion.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, m, i, j;
cin>>n>>m;
for (i = 1; i <= n; i++) {
fa[i]=i;
}
for (i = 0; i < m; i++) {
int x,y;
cin>>x>>y;
join(x,y);
}
int ans=0;
for (i=1;i<=n;i++) {
// cout<<i<<" "<<fa[i]<<endl;
if (find(i)==i) {
// cout<<find(i)<<endl;
ans++;
}
}
cout<<ans<<endl;
return 0;
}