#include <bits/stdc++.h>
using namespace std;
const int NUM = 2e5 + 5;
long long int n, m;
vector<long long int> g[NUM];
bool vis[NUM];
long long int siz, edges;
void dfs(long long int node) {
  vis[node] = 1;
  siz++;
  edges += g[node].size();
  for (auto x : g[node]) {
    if (!vis[x]) dfs(x);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int num_tests = 1;
  while (num_tests-- > 0) {
    cin >> n >> m;
    for (long long int i = 0; i < m; i++) {
      long long int x, y;
      cin >> x >> y;
      g[x].push_back(y);
      g[y].push_back(x);
    }
    memset(vis, 0, sizeof(vis));
    long long int ans = 0;
    for (long long int i = 1; i < n + 1; i++) {
      if (!vis[i]) {
        siz = 0, edges = 0;
        dfs(i);
        edges = edges / 2;
        if (edges == siz - 1) ans++;
      }
    }
    cout << ans;
  }
}
