#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > components;
vector<vector<int> > g;
vector<int> component;
vector<int> p, s;
map<int, bool> used;
int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); }
void union_sets(int a, int b) {
  int x = get(a);
  int y = get(b);
  if (x != y) {
    if (s[x] < s[y]) {
      swap(x, y);
    }
    p[y] = x;
    s[x] += s[y];
  }
  return;
}
void dfs(int x) {
  used[x] = true;
  component.push_back(x);
  for (auto to : g[x]) {
    if (!used[to]) {
      dfs(to);
    }
  }
  return;
}
bool flag;
void cyclic(int x, int last) {
  used[x] = true;
  for (auto to : g[x]) {
    if (!used[to]) {
      cyclic(to, x);
    } else {
      if (to != last) {
        flag = false;
        return;
      }
    }
  }
  return;
}
int execute() {
  int n, m;
  cin >> n >> m;
  g.resize(n + 1);
  p.resize(n + 1);
  s.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    s[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
    union_sets(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      component.clear();
      dfs(i);
      components.push_back(component);
    }
  }
  used.clear();
  int cnt = 0;
  for (auto xt : components) {
    for (auto x : xt) {
      if (x == get(x)) {
        flag = true;
        cyclic(x, x);
        cnt += flag;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
int TE = true;
bool mTest = false;
int main() {
  ios_base::sync_with_stdio(false);
  if (mTest) cin >> TE;
  while (TE--) {
    execute();
  }
  return 0;
}
