#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
vector<int> adj[MAXN];
bool mark[MAXN];
bool fl = false;
vector<int> q;
int p[MAXN];
long long int mod = 1000 * 1000 * 1000 + 7;
void addEdge(long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void BFS(int u) {
  mark[u] = true;
  q.push_back(u);
  p[u] = u;
  while (!q.empty()) {
    int x = q.back();
    q.pop_back();
    for (int i = 0; i < adj[x].size(); i++) {
      int y = adj[x][i];
      if (!mark[y]) {
        mark[y] = true;
        q.push_back(y);
        p[y] = x;
      } else if (p[x] != y) {
        fl = true;
      }
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    addEdge(x, y);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) {
      fl = false;
      BFS(i);
      if (!fl) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
