#include <bits/stdc++.h>
using namespace std;
int boss[100005];
int n, k, ans = 0;
int find(int x) {
  if (boss[x] == x) return x;
  return boss[x] = find(boss[x]);
}
int main() {
  for (int i = 0; i < 100005; i++) boss[i] = i;
  cin >> n >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    a = find(a);
    b = find(b);
    if (a == b) ans++;
    boss[a] = b;
  }
  cout << ans << endl;
}
