#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
int numnodes;
int numedges;
bool vis[100005];
void dfs(int n) {
  if (vis[n]) return;
  vis[n] = 1;
  numnodes++;
  numedges += edges[n].size();
  for (int i = 0; i < edges[n].size(); i++) {
    int ne = edges[n][i];
    if (!vis[ne]) {
      dfs(ne);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) edges[i] = vector<int>();
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      edges[x].push_back(y);
      edges[y].push_back(x);
    }
    int res = 0;
    memset((vis), 0, sizeof((vis)));
    for (int i = 0; i < n; i++) {
      if (!vis[i]) {
        numnodes = 0;
        numedges = 0;
        dfs(i);
        numedges /= 2;
        if (numedges + 1 == numnodes) {
          res++;
        }
      }
    }
    cout << res << endl;
  }
}
