#include <bits/stdc++.h>
using namespace std;
int vis[200001] = {0};
vector<int> v[200001];
int main() {
  int n, m, x, y, c = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  vector<int> q;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      q.push_back(i);
      int j = 0, tag1 = true;
      while (1) {
        int k = q[j];
        int tag = true;
        vis[k] = 2;
        for (int l = 0; l < v[k].size(); l++) {
          if (vis[v[k][l]] == 1)
            tag1 = false;
          else if (vis[v[k][l]] == 0) {
            q.push_back(v[k][l]);
            tag = false;
            vis[v[k][l]] = 1;
          }
        }
        if (tag == true && j == q.size() - 1) break;
        j++;
      }
      if (tag1 == true) c++;
    }
    q.clear();
  }
  cout << c;
}
