#include <iostream>
#include <vector>
#include <fstream>
std::vector<int>* L;
std::vector<bool> viz;
std::ifstream fin("dfs.in");
std::ofstream fout("dfs.out");
void DFS(int i)
{
viz[i] = 1;
for (auto e : L[i])
if (!viz[e])
DFS(e);
}
int main()
{
int n, m, x, y;
fin >> n >> m;
L = new std::vector<int>[n+1];
for (int i = 1; i <= m; i++)
{
fin >> x >> y;
L[x].push_back(y);
L[y].push_back(x);
}
viz.resize(n+1, 0);
x = 0;
for (int i = 1; i <= n; i++)
if (!viz[i])
{ x++; DFS(i); }
fout << x;
return 0;
}