#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}
long long int power(long long int a, long long int b) {
  long long int x = 1;
  long long int y = a;
  while (b > 0) {
    if (b & 1) {
      x = x * y;
      x %= 1000000007;
    }
    y = y * y;
    y %= 1000000007;
    b /= 2;
  }
  return x;
}
long long int inver(long long int a) { return power(a, 1000000007 - 2); }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int n, m;
bool visi[100010];
int dsu[100010];
void pre() {
  for (int i = 1; i <= n; i++) {
    dsu[i] = i;
  }
}
int root(int x) {
  while (x != dsu[x]) {
    dsu[x] = dsu[dsu[x]];
    x = dsu[x];
  }
  return x;
}
int main() {
  scanf("%d%d", &n, &m);
  pre();
  vector<int> ci;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int root_x = root(x);
    int root_y = root(y);
    if (root_x == root_y) {
      visi[root_x] = true;
      ci.push_back(root_x);
    } else {
      dsu[root_x] = root_y;
    }
  }
  for (int i = 0; i < ci.size(); i++) {
    visi[root(ci[i])] = true;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int root_x = root(i);
    if (visi[i] == true) {
      visi[root_x] = true;
    }
    if (visi[root_x] == false) {
      ans++;
      visi[root_x] = true;
    }
  }
  cout << ans << endl;
  return 0;
}
