#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
vector<pair<int, int> > my;
int n, m, count1[100005], ans = 0, nodes, edges;
bool visited[100005];
void dfs(int s, int p) {
  bool flag = true;
  visited[s] = true;
  edges += count1[s];
  nodes++;
  for (int i = 0; i < v[s].size(); ++i) {
    if (!visited[v[s][i]]) {
      visited[v[s][i]] = true;
      dfs(v[s][i], s);
    }
  }
}
bool cmpr(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second > b.second;
  } else
    return a.first < b.first;
}
int main() {
  int x, y;
  cin >> n >> m;
  memset(count1, 0, sizeof(count1));
  memset(visited, false, sizeof(visited));
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    count1[y]++;
    count1[x]++;
  }
  for (int i = 1; i <= n; i++) {
    my.push_back(make_pair(i, count1[i]));
  }
  for (int i = 0; i < my.size(); ++i) {
    if (!visited[my[i].first]) {
      nodes = 0;
      edges = 0;
      dfs(my[i].first, 0);
      if (edges / 2 + 1 == nodes) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
