#include <bits/stdc++.h>
using namespace std;
vector<int> vv[1000005];
bool visited[1000005];
map<int, int> mp;
int calcuculateVal(int src) {
  queue<pair<int, int> > q;
  int level = 1;
  q.push(make_pair(src, level));
  visited[src] = true;
  bool isCyclic = false;
  while (!q.empty()) {
    pair<int, int> front = q.front();
    q.pop();
    for (vector<int>::iterator itr = vv[front.first].begin();
         itr != vv[front.first].end(); itr++) {
      if (visited[*itr] == false) {
        visited[*itr] = true;
        q.push(make_pair(*itr, front.second + 1));
        mp[*itr] = front.first;
      } else {
        if (mp[front.first] != *itr) {
          isCyclic = true;
        }
      }
    }
  }
  if (isCyclic) {
    return 0;
  }
  return 1;
}
int main() {
  int n = -1, m = -1;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int start, end;
    scanf("%d %d", &start, &end);
    vv[start].push_back(end);
    vv[end].push_back(start);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false) {
      ans += calcuculateVal(i);
    }
  }
  cout << ans;
  return 0;
}
