#include <bits/stdc++.h>
const int M = 1e9 + 7;
const int N = 1e5 + 5;
using namespace std;
vector<long long int> v[N];
long long int indeg[26];
long long int vis[N], edge, ver;
bool cycle(long long int x) {
  if (vis[x] == 2) return false;
  if (vis[x] == 1) return true;
  vis[x] = 1;
  for (auto f : v[x]) {
    if (cycle(f)) return true;
  }
  vis[x] = 2;
  return false;
}
void dfs(long long int x) {
  if (vis[x]) return;
  vis[x] = 1;
  ++ver;
  edge += v[x].size();
  for (auto y : v[x]) {
    dfs(y);
  }
}
int main() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; ++i) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      ver = 0, edge = 0;
      dfs(i);
      edge /= 2;
      ans += (edge < ver);
    }
  }
  cout << ans << "\n";
}
