#include <iostream>
using namespace std;
int search(int x)
{
if (f(x) != x)
f(x) = search(f(x))
return f(x);
}
int marge(int x,int y)
{
f(search(x)) = search(y);
}
int main()
{
freopen("religion.in","r",stdin);
freopen("religion.out","w",stdout);
int n,m;
cin >> n >> m;
int *f[] = new int [n];
for (int i = 0;i < n;++i)
f[i] = i;
int x,y;
for (int i = 0;i < m;++i)
{
cin >> x >> y;
marge(x,y);
}
int num = 0;
for (int i = 0;i < n;++i)
if (f(x) = x)
++num;
cout << num;
return 0;
}