#include <iostream>
#include <algorithm>
#include <stack>
#include <cstring>
#include <vector>
#include <fstream>
#include <queue>
#include <bitset>
#define pb push_back
#define mp make_pair
#define dim 100009
using namespace std;
ofstream out("dfs.out");
int n,m;
bitset<dim> uz;
int sol;
vector < int > G[dim];
typedef vector < int >::iterator IT;
void read();
void dfs(int source);
void iterativeDfs(int source);
int main()
{
read();
for(int i = 1 ; i<=n; ++i)
if(!uz[i])
{
++sol;
iterativeDfs(i);
}
out << sol << '\n';
return 0;
}
void read()
{
ifstream in("dfs.in");
in >> n >> m;
for(int x,y; m; --m)
{
in >> x >> y;
G[x].pb(y);
G[y].pb(x);
}
}
void dfs(int source)
{
uz[source] = 1;
for(IT i = G[source].begin(); i!=G[source].end(); ++i)
if(!uz[*i])
{
dfs(*i);
}
}
void iterativeDfs(int source)
{
stack<int> St;
St.push(source);
uz[source] = 1;
while(!St.empty())
{
int vf = St.top();
int ans = -1;
for(IT i = G[vf].begin(); i!=G[vf].end(); ++i)
{
if(!uz[*i])
{
ans = *i;
break;
//am gasit un vecin ok
}
}
if(ans != -1)
{
St.push(ans);
uz[ans] = 1;
}
else
{
St.pop();
}
}
}