#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[100005];
int edges, vertices;
void dfs(bool vis[], int src) {
  vis[src] = true;
  vertices++;
  for (int i = 0; i < adj[src].size(); i++) {
    edges++;
    if (!vis[adj[src][i]]) dfs(vis, adj[src][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int ans = 0;
  bool vis[n];
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      edges = 0;
      vertices = 0;
      dfs(vis, i);
      if (edges / 2 == vertices - 1) ans++;
    }
  }
  cout << ans;
  return 0;
}
