#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans;
map<pair<int, int>, bool> V;
void dfs2(map<int, vector<int>>& g, int u, bool* visited, int& ec) {
  visited[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!V[{u, v}]) {
      V[{u, v}] = true;
      V[{v, u}] = true;
      ec++;
    }
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!visited[v]) {
      dfs2(g, v, visited, ec);
    }
  }
}
void dfs(map<int, vector<int>>& g, int u, vector<int>& tmp, bool* visited) {
  visited[u] = true;
  tmp.push_back(u);
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!visited[v]) {
      dfs(g, v, tmp, visited);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> g;
  while (m--) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bool visited[n + 1];
  for (int i = 0; i <= n; i++) visited[i] = false;
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      vector<int> tmp;
      dfs(g, i, tmp, visited);
      ans.push_back(tmp);
    }
  }
  int finalans = 0;
  int r = ans.size();
  for (int i = 1; i <= n; i++) {
    visited[i] = false;
  }
  for (int i = 0; i < r; i++) {
    int src = ans[i][0];
    int ec = 0;
    dfs2(g, src, visited, ec);
    if (ec == ans[i].size() - 1) {
      finalans += 1;
    } else {
      finalans += 0;
    }
  }
  cout << finalans << endl;
  return 0;
}
