#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &);
template <size_t n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
                                                  const tuple<T...> &) {}
template <size_t n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
                                                 const tuple<T...> &t) {
  os << (n == 0 ? "" : " ") << get<n>(t);
  _ot<n + 1>(os, t);
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &t) {
  _ot<0>(os, t);
  return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (size_t i = 0; i < v.size(); i++)
    os << v[i] << (i + 1 == v.size() ? "" : ", ");
  return os;
}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
void fastios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
struct UnionFind {
  vector<int> par;
  int cnt;
  UnionFind(int size_) : par(size_, -1), cnt(size_) {}
  void unite(int x, int y) {
    if ((x = find(x)) != (y = find(y))) {
      if (par[y] < par[x]) swap(x, y);
      par[x] += par[y];
      par[y] = x;
      cnt--;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
  int size(int x) { return -par[find(x)]; }
  int size() { return cnt; }
};
int main() {
  int n, m;
  while (cin >> n >> m) {
    vector<int> u(m), v(m);
    UnionFind uf(n);
    vector<int> deg(n);
    for (int i = 0; i < (int)(m); i++) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      uf.unite(a, b);
      ++deg[a];
      ++deg[b];
    }
    int ans = 0;
    map<int, vector<int>> comps;
    for (int i = 0; i < (int)(n); i++) {
      comps[uf.find(i)].emplace_back(i);
    }
    for (auto &e : comps) {
      auto &comp = e.second;
      int degsum = 0;
      for (int v : comp) {
        degsum += deg[v];
      }
      int E = degsum / 2;
      int V = comp.size();
      if (E == V - 1) {
        ++ans;
      }
    }
    cout << ans << endl;
  }
}
