#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(100005);
int visited[100005];
map<pair<long long, long long>, int> mapping;
int nodes, edges;
void dfs(int start) {
  nodes++;
  visited[start] = 1;
  int i;
  for (i = 0; i < v[start].size(); i++) {
    if (!visited[v[start][i]]) {
      edges++;
      mapping[pair<long long, long long>(start, v[start][i])] = 1;
      dfs(v[start][i]);
    } else if (mapping[pair<long long, long long>(start, v[start][i])] == 0 &&
               mapping[pair<long long, long long>(v[start][i], start)] == 0) {
      mapping[pair<long long, long long>(start, v[start][i])] = 1;
      edges++;
    }
  }
}
int main() {
  int i, j, n, m, ans, a, b;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (visited[i]) continue;
    nodes = 0;
    edges = 0;
    dfs(i);
    if (nodes - 1 == edges) ans++;
  }
  cout << ans;
  return 0;
}
