#include<iostream>
#include<cstdio>
using namespace std;
int a[50010];
int find(int x)
{
if (a[x] != x)
return a[x]=find(a[x]);
return a[x];
}
void unionn(int x,int y)
{
x = find(x);
y = find(y);
a[y] = x;
}
int main()
{
freopen("religion.in", "r", stdin);
freopen("religion.out", "w", stdout);
int n, m, x, y,sum=0;
cin >> n >> m;
for (int i = 1; i <= n; i++)
a[i] = i;
for (int i = 0; i < m; i++)
{
scanf("%d%d", &x, &y);
unionn(x, y);
}
for (int i = 1; i <= n; i++)
{
if (a[i] == i)
sum++;
}
cout << sum;
return 0;
}