#include <bits/stdc++.h>
using namespace std;
string gs(char x) {
  string s(1, x);
  return s;
}
vector<long long> v[100001];
bool vis[100001];
long long numnode, numedge;
void dfs(long long c) {
  numnode++;
  numedge += v[c].size();
  vis[c] = true;
  for (long long i = 0; i < v[c].size(); i++) {
    if (!vis[v[c][i]]) {
      dfs(v[c][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long a, b;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      numedge = 0;
      numnode = 0;
      dfs(i);
      numedge /= 2;
      if (numnode == numedge + 1) ans += 1;
    }
  }
  cout << ans;
  return 0;
}
