#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, ans, nodes, edges;
vector<vector<int> > adjList(100002);
bool vis[100002];
void dfs(int i) {
  vis[i] = true;
  nodes++;
  for (int j = 0; j <= (int)adjList[i].size() - 1; j++) {
    edges++;
    if (!vis[adjList[i][j]]) dfs(adjList[i][j]);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= (int)m; i++) {
    scanf("%d %d", &x, &y);
    adjList[x].push_back(y);
    adjList[y].push_back(x);
  }
  for (int i = 1; i <= (int)n; i++) {
    nodes = 0;
    edges = 0;
    if (!vis[i]) {
      dfs(i);
      if (nodes - 1 == edges / 2) ans++;
    }
  }
  cout << ans;
}
