/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
vector<int> l[10001];
int vis[10001];
void dfs(int node) {
vis[node] = 1;
for(auto vec : l[node]) {
if(vis[vec] == 0){
dfs(vec);
}
}
}
int main()
{
int n,m;
cin>> n >>m;
for(int i = 1; i <= m; i++) {
int a,b;
cin >> a >>b;
L[a].push_back(b);
L[b].push_back(a);
}
int nr = 0;
for(int i = 1; i <= n; i++){
if(vis[i] == 0){
nr++;
dfs(i);
}
}
cout << nr;
}
return 0;