#include <bits/stdc++.h>
using namespace std;
bool visited[100005] = {false};
bool isTree(int root, int parent, vector<int> adjlist[]) {
  if (visited[root]) return false;
  if (adjlist[root].empty()) {
    visited[root] = true;
    return true;
  }
  bool res = true;
  visited[root] = true;
  for (int i = 0; i < adjlist[root].size() && res; i++) {
    int v = adjlist[root][i];
    if (v != parent) res = isTree(v, root, adjlist);
  }
  return res;
}
int main() {
  int m, n, u, v, t, res = 0;
  cin >> n >> m;
  vector<int> adjlist[n + 1];
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adjlist[u].push_back(v);
    adjlist[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      if (isTree(i, -1, adjlist)) res++;
    }
  }
  cout << res << endl;
  return 0;
}
