int main() {
  int cc = 0, n, m;
  cin >> n >> m;
  vector<bool> marked(n, 0); // g++, not msvc
  vector<int> c[n];
  auto dfs = [&]( int v ) {
    if (marked[v]) return;
    marked[v] = 1;
    for (int x : c[v]) dfs(x);
  };
  while (m--) {
    int a, b;
    cin >> a >> b, a--, b--; // 1..n
    c[a].push_back(b);
    c[b].push_back(a);
  }
  for (int i = 0; i < n; i++)
    if (!marked[i])
      cc++, dfs(i);
}