#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int n, m, x, y, z, t, h[N];
vector<int> v[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (h[i]) continue;
    queue<int> q;
    int t = 0, s = 0;
    q.push(i);
    h[i] = 1;
    while (q.size()) {
      int node = q.front();
      q.pop();
      s++;
      t += v[node].size();
      for (__typeof(v[node].begin()) it = v[node].begin(); it != v[node].end();
           it++)
        if (!h[*it]) {
          q.push(*it);
          h[*it] = 1;
        }
    }
    t /= 2;
    if (t + 1 == s) ans++;
  }
  cout << ans << '\n';
  return 0;
}
