#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
bitset<(int)1e6> us;
bool isCyclic(int v, int p = -1) {
  us.set(v);
  for (int i = 0; i < g[v].size(); i++) {
    if (us.test(g[v][i]) && g[v][i] != p) return 0;
    if (us.test(g[v][i])) continue;
    bool cures = isCyclic(g[v][i], v);
    if (!cures) return 0;
  }
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int v, to;
    cin >> v >> to;
    g[to].push_back(v);
    g[v].push_back(to);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (us.test(i)) continue;
    sum += isCyclic(i);
  }
  cout << sum << endl;
}
