#include <bits/stdc++.h>
using namespace std;
void addEdge(vector<long long> adj[], long long u, long long v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void DFSUtil(vector<long long> adj[], long long v, bool visited[]) {
  visited[v] = true;
  for (long long i = 0; i < adj[v].size(); ++i)
    if (!visited[adj[v][i]]) DFSUtil(adj, adj[v][i], visited);
}
long long f1(vector<long long> adj[], long long n) {
  bool* visited = new bool[n];
  long long count = 0;
  for (long long v = 0; v < n; v++) visited[v] = false;
  for (long long v = 0; v < n; v++) {
    if (visited[v] == false) {
      DFSUtil(adj, v, visited);
      count += 1;
    }
  }
  return count;
}
bool isCyclicUtil(vector<long long> adj[], long long v, bool visited[],
                  long long parent) {
  bool flag = false;
  visited[v] = true;
  for (long long i = 0; i < adj[v].size(); ++i) {
    if (!visited[adj[v][i]]) {
      if (isCyclicUtil(adj, adj[v][i], visited, v)) flag = true;
    } else if (adj[v][i] != parent)
      flag = true;
  }
  return flag;
}
long long isCyclic(vector<long long> adj[], long long n) {
  bool* visited = new bool[n];
  for (long long i = 0; i < n; i++) visited[i] = false;
  long long ans = 0;
  for (long long u = 0; u < n; u++) {
    if (!visited[u]) {
      if (isCyclicUtil(adj, u, visited, -1)) {
        ans++;
      }
    }
  }
  return ans;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> adj[n];
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long x = f1(adj, n);
  long long y = isCyclic(adj, n);
  cout << x - y << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
