#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(100005 + 1);
vector<int> vis(100005 + 1, 0);
vector<int> group;
void dfs(int i) {
  for (int j = 0; j < v[i].size(); j++) {
    if (vis[v[i][j]] == 0) {
      group.push_back(v[i][j]);
      vis[v[i][j]] = 1;
      dfs(v[i][j]);
    }
  }
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      count++;
      group.clear();
      group.push_back(i);
      vis[i] = 1;
      dfs(i);
      int counter = 0;
      for (int o = 0; o < group.size(); o++) {
        counter += v[group[o]].size();
      }
      counter /= 2;
      if (counter >= group.size()) {
        count--;
      }
    }
  }
  cout << count << endl;
  return 0;
}
