#include <bits/stdc++.h>
using namespace std;
vector<int> graph[10000001];
int vis[1000001], parent[1000001], k = 1, cnt = 0;
void iscycle(int start) {
  vis[start] = 1;
  for (int i = 0; i < graph[start].size(); i++) {
    if (vis[graph[start][i]] == 1 && parent[start] != graph[start][i]) {
      k = 0;
    } else if (vis[graph[start][i]] == 0) {
      parent[graph[start][i]] = start;
      iscycle(graph[start][i]);
    }
  }
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      iscycle(i);
      if (k == 0) {
        k = 1;
      } else {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
