#include <fstream>
#include <vector>
std::ifstream fin("dfs.in");
std::ofstream fout("dfs.out");
void dfs(int start, std::vector<int> &visited, const std::vector<std::vector<int>> &graph) {
if (visited[start] != 1) {
visited[start] = 1;
for (int vecin : graph[start]) {
if (visited[vecin] != 1) {
dfs(vecin, visited, graph);
}
}
}
}
int main() {
int x, y, n, m, nrConex = 0;
fin >> n >> m;
std::vector<int> visited(n+1, 0);
std::vector<std::vector<int>> nodesList(n+1);
while (fin >> x >> y) {
nodesList[x].push_back(y);
nodesList[y].push_back(x);
}
for (int i = 1; i <= n; i++) {
if (visited[i] != 1) {
nrConex ++;
dfs(i, visited, nodesList);
}
}
fout << nrConex;
}