#include <bits/stdc++.h>
using namespace std;
int visited[100005], parent[100005];
vector<int> graph[100005];
bool hasCycle;
void dfs(int node) {
  int i, temp;
  for (i = 0; i < graph[node].size(); i++) {
    temp = graph[node][i];
    if (visited[temp] == 0) {
      visited[temp] = 1;
      parent[temp] = node;
      dfs(temp);
    } else if ((visited[temp] == 1) && (parent[node] != temp))
      hasCycle = false;
  }
  return;
}
int main() {
  int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, result = 0, cnt;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    graph[l].push_back(r);
    graph[r].push_back(l);
  }
  for (i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      visited[i] = 1;
      hasCycle = true;
      dfs(i);
      result = result + hasCycle;
    }
  }
  printf("%d\n", result);
  return 0;
}
