#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
const int MaxN = 100005;
vector<int> G[MaxN];
int N, M;
bool v[MaxN];
void Read();
void DFS(int x);
int main()
{
Read();
int cnt = 0;
for(int i = 1; i <= N; ++i)
if(!v[i])
{
DFS(i);
++cnt;
}
fout << cnt << '\n';
fout.close();
return 0;
}
void Read()
{
fin >> N >> M;
while(M--)
{
int x, y;
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
fin.close();
}
void DFS(int x)
{
v[x] = true;
for(const int y : G[x])
if(!v[y])
DFS(y);
}