#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100100;
int N, M;
int cnt = -1;
bool been[MaxN];
vector<int> adj[MaxN];
vector<int> Ver[MaxN];
int beenKomp[MaxN];
bool dfsKomp(int i) {
  bool ret = 1;
  beenKomp[i] = 1;
  for (auto v : adj[i]) {
    if (!beenKomp[v]) {
      ret &= dfsKomp(v);
    } else if (beenKomp[v] == 2) {
      ret &= 0;
    }
  }
  beenKomp[i] = 2;
  return ret;
}
void dfs(int i) {
  been[i] = 1;
  for (auto v : adj[i]) {
    if (!been[v]) dfs(v);
  }
  Ver[cnt].push_back(i);
}
int main() {
  cin >> N >> M;
  int ta, tb;
  for (int i = (0); i < (M); i++) {
    scanf("%d%d", &ta, &tb);
    ta--;
    tb--;
    adj[ta].push_back(tb);
    adj[tb].push_back(ta);
  }
  for (int i = (0); i < (N); i++) {
    if (!been[i]) {
      cnt++;
      dfs(i);
    }
  }
  int sol = 0;
  for (int k = (0); k < (cnt + 1); k++) {
    if (dfsKomp(Ver[k][0])) sol++;
  }
  cout << sol << endl;
  return 0;
}
