#include <bits/stdc++.h>
using namespace std;
const int N = 500009;
const int mod = 1000000007;
int n, m, x, y;
vector<int> v[N];
vector<bool> vis;
bool is;
void pre() { vis.assign(N, 0); }
void dfs(int ver, int par) {
  vis[ver] = 1;
  for (auto &it : v[ver]) {
    if (it == par) continue;
    if (vis[it] == 1) {
      is = 1;
      continue;
    }
    dfs(it, ver);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(cin.failbit);
  ;
  pre();
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    is = 0;
    dfs(i, -1);
    ans++;
    if (is) ans--;
  }
  cout << ans << "\n";
  return 0;
}
