#include <bits/stdc++.h>
using namespace std;
int dcmp(long double n, long double y) {
  return fabs(n - y) <= 1e-9 ? 0 : n < y ? -1 : 1;
}
const int MAX = 1e5 + 10;
int n, m, ans;
vector<vector<int> > adj;
bool vis[MAX];
int edges;
int dfs(int node) {
  vis[node] = 1;
  int ret = 1;
  edges += adj[node].size();
  for (int i = 0; i < ((int)((adj[node]).size())); ++i) {
    int child = adj[node][i];
    if (!vis[child]) ret += dfs(child);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  adj = vector<vector<int> >(n);
  for (int i = 0; i < (int)(m); ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (!vis[i]) {
      edges = 0;
      int o = dfs(i);
      int y = edges / 2;
      if (o - 1 == y) ans++;
    }
  }
  cout << ans << '\n';
}
