#include <bits/stdc++.h>
using namespace std;
bool flag;
vector<vector<int> > g;
map<int, bool> used;
void dfs(int x, int last) {
  used[x] = true;
  for (auto to : g[x]) {
    if (!used[to]) {
      dfs(to, x);
    } else {
      if (last != to) {
        flag = false;
        return;
      }
    }
  }
  return;
}
int execute() {
  int n, m;
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      flag = true;
      dfs(i, i);
      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;
}
