#include <bits/stdc++.h>
using namespace std;
long long root(long long x, long long par[]) {
  if (x == par[x]) return x;
  return par[x] = root(par[x], par);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, i, j, ans = 0;
  cin >> n >> m;
  long long par[n + 2], sz[n + 2];
  for (i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    long long px = root(x, par), py = root(y, par);
    if (px == py)
      ans++;
    else {
      if (sz[px] < sz[py]) swap(px, py);
      sz[px] += sz[py];
      par[px] = py;
    }
  }
  cout << ans;
}
