#include <bits/stdc++.h>
using namespace std;
int root[100010], deg[100010], cnt[100010];
int find_root(int u) {
  if (u == root[u]) return u;
  return root[u] = find_root(root[u]);
}
int main() {
  int N, M, u, v, ans, i;
  scanf("%d%d", &N, &M);
  for (i = 0; i < N; i++) root[i] = i;
  for (i = 0; i < M; i++) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    deg[u]++;
    deg[v]++;
    int uu = find_root(u);
    int vv = find_root(v);
    if (uu == vv) continue;
    root[uu] = vv;
  }
  for (i = 0; i < N; i++) {
    u = find_root(i);
    cnt[u]++;
    if (u == i) continue;
    deg[u] += deg[i];
  }
  ans = 0;
  for (i = 0; i < N; i++) {
    u = find_root(i);
    if (u != i) continue;
    if (deg[u] == 2 * (cnt[u] - 1)) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
