#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> g[100010];
vector<bool> vis(1e5 + 10, false);
long long edges, nodes;
void dfs(int i) {
  if (vis[i]) {
    return;
  }
  vis[i] = true;
  nodes++;
  edges += g[i].size();
  for (auto j : g[i]) {
    dfs(j);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      edges = 0;
      nodes = 0;
      dfs(i);
      edges /= 2;
      if (edges < nodes) ans++;
    }
  }
  cout << ans;
  return 0;
}
