#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
const int INF = 1e9 + 7;
const long long int LINF = 1e18;
const long long int MOD = 1e9 + 7;
using namespace std;
vector<int> a[MAXN];
vector<int> topsort;
int used[MAXN];
bool good = false;
void dfs2(int x, int p = -1) {
  used[x] = 1;
  for (auto i : a[x]) {
    if (i == p) {
      continue;
    }
    if (used[i] == 1) {
      good = true;
    } else if (used[i] == 0) {
      dfs2(i, x);
    }
  }
  used[x] = 2;
}
void dfs(int x, int p = -1) {
  used[x] = 1;
  for (auto i : a[x]) {
    if (i == p) {
      continue;
    }
    if (used[i] == 1) {
      good = true;
    } else if (used[i] == 0) {
      dfs(i, x);
    }
  }
  used[x] = 2;
  topsort.push_back(x);
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      dfs(i);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    used[i] = 0;
  }
  reverse(topsort.begin(), topsort.end());
  for (auto i : topsort) {
    good = false;
    if (!used[i]) {
      dfs2(i);
      if (!good) {
        ans++;
      }
    }
  }
  printf("%d", ans);
  return 0;
}
