#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("religion.in", "r", stdin);
auto OUT = freopen("religion.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 5e4 + 5;
int n = mread(), m = mread(), fa[N];
int findfa(int x){
if(x == fa[x]){
return x;
}
return fa[x] = findfa(fa[x]);
}
signed main(){
for(int i = 1; i <= n; i ++){
fa[i] = i;
}
for(int i = 1, x, y; i <= m; i ++){
x = mread(), y = mread();
fa[findfa(x)] = findfa(y);
}
set<int> s;
for(int i = 1; i <= n; i ++){
s.insert(findfa(i));
}
printf("%lld", (int)s.size());
return 0;
}