#include <bits/stdc++.h>
using namespace std;
bool visited[100005];
vector<long long> mp[100005];
long long res = 0;
long long ans = 0;
const long long U = 1e8 + 7;
void dfs(long long second) {
  visited[second] = true;
  ans++;
  for (int i = 0; i < mp[second].size(); i++) {
    res++;
    if (visited[mp[second][i]] == false) {
      dfs(mp[second][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  memset(visited, false, sizeof visited);
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    mp[a].push_back(b);
    mp[b].push_back(a);
  }
  long long x = 0;
  for (int i = 0; i < n; i++) {
    if (visited[i] == false) {
      res = 0;
      ans = 0;
      dfs(i);
      res = res / 2;
      if (res == ans - 1) x++;
    }
  }
  cout << x - 1;
  return 0;
}
