//KZNS
//Best WiL
#include <cstdio>
#define Nmax 50003
int N, M;
int ans;
int fa[Nmax];
int FA(int x) {
if (fa[x] != x)
fa[x] = FA(fa[x]);
return fa[x];
}
int main() {
freopen("religion.in", "r", stdin);
freopen("religion.out", "w", stdout);
scanf("%d %d", &N, &M);
ans = N;
for (int i = 1; i <= N; i++)
fa[i] = i;
int a, b;
for (int i = 0; i < M; i++) {
scanf("%d %d", &a, &b);
if (FA(a) != FA(b)) {
ans--;
fa[fa[a]] = fa[b];
}
}
printf("%d\n", ans);
return 0;
}
//All Illu
//UBWH