#include <bits/stdc++.h>
using namespace std;
long long n, m, u, v, edges, ans;
vector<long long> adj[100001], nodes;
bool visit[100001];
void dfs(int node) {
  nodes.push_back(node);
  visit[node] = 1;
  for (long long i = 0; i < adj[node].size(); i++) {
    if (!visit[adj[node][i]]) dfs(adj[node][i]);
  }
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (long long i = 1; i <= n; i++) {
    if (!visit[i]) {
      nodes.clear();
      edges = 0;
      dfs(i);
      for (long long i = 0; i < nodes.size(); i++)
        edges += adj[nodes[i]].size();
      if (edges / 2 < nodes.size()) ans++;
    }
  }
  cout << ans;
}
