#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
vector<bool> vis;
long long v, e;
void dfs(long long k, long long par) {
  queue<pair<long long, long long>> q;
  q.push({k, par});
  vis[k] = true;
  while (!q.empty()) {
    k = q.front().first;
    par = q.front().second;
    q.pop();
    for (auto it : adj[k]) {
      if (it != par) {
        if (!vis[it]) {
          vis[it] = true;
          q.push({it, k});
          v++;
          e++;
        } else
          e++;
      }
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, p, q;
  cin >> n >> m;
  adj = vector<vector<long long>>(n + 1);
  for (long long i = 0; i < m; i++) {
    cin >> p >> q;
    adj[p].push_back(q);
    adj[q].push_back(p);
  }
  long long c = 0;
  vis = vector<bool>(n + 1, false);
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      v = 1, e = 0;
      dfs(i, -1);
      if (v == e + 1) c++;
    }
  }
  cout << c << '\n';
  return 0;
}
