#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
inline long long MAX(long long a, long long b) { return (a > b) ? (a) : (b); }
inline long long MIN(long long a, long long b) { return (a < b) ? (a) : (b); }
void ex() {
  cout << "NO";
  exit(0);
}
int const sz = 2e5 + 3;
int label[sz + 1];
vector<int> comp[sz + 1];
vector<int> con[sz + 1];
void dfs(int a, int lab) {
  for (std::vector<int>::iterator it = con[a].begin(); it != con[a].end();
       ++it) {
    int u = *it;
    if (label[u] > 0) continue;
    comp[lab].push_back(u);
    label[u] = lab;
    dfs(u, lab);
  }
}
int main() {
  int i, j, n, m, a, b;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    con[a].push_back(b);
    con[b].push_back(a);
  }
  for (i = 0; i <= n; i++) label[i] = 0;
  int lab = 0;
  for (i = 1; i <= n; i++)
    if (label[i] == 0) {
      lab++;
      label[i] = lab;
      comp[lab].push_back(i);
      dfs(i, lab);
    }
  long long edge;
  int ans = 0;
  for (i = 1; i <= lab; i++) {
    edge = 0;
    for (std::vector<int>::iterator it = comp[i].begin(); it != comp[i].end();
         ++it) {
      edge += con[*it].size();
    }
    if (comp[i].size() == edge / 2 + 1) ans++;
  }
  cout << ans;
  return 0;
}
