#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
pair<long long, long long> x1[300000];
vector<long long> v[300000];
long long f[300000];
long long kolver[300000];
long long koledg[300000];
long long kol = 0;
void dfs(long long xx) {
  if (f[xx]) return;
  f[xx] = kol;
  for (int i = 0; i < v[xx].size(); i++) dfs(v[xx][i]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  long long n, m, i, a, b, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    x1[i] = make_pair(a, b);
  }
  for (int i = 1; i <= n; i++)
    if (!f[i]) {
      kol++;
      dfs(i);
    }
  for (int i = 1; i <= n; i++) kolver[f[i]]++;
  for (int i = 1; i <= m; i++) {
    a = x1[i].first;
    b = x1[i].second;
    koledg[f[a]]++;
  }
  for (int i = 1; i <= kol; i++)
    if (koledg[i] == kolver[i] - 1) ans++;
  cout << ans << endl;
  return 0;
}
