#include <bits/stdc++.h>
using namespace std;
long long int arr[100002];
long long int sizee[100002];
long long int par(long long int a) {
  long long int x = a;
  while (x != arr[x]) {
    x = arr[x];
  }
  return x;
}
void join(long long int p, long long int q) {
  long long int p1 = par(p);
  long long int q1 = par(q);
  if (sizee[p1] >= sizee[q1]) {
    arr[q1] = p1;
    sizee[p1] += sizee[q1];
  } else {
    arr[p1] = q1;
    sizee[q1] += sizee[p1];
  }
}
int main() {
  long long int n, k;
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) {
    arr[i] = i;
    sizee[i] = 1;
  }
  long long int cnt = 0;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    long long int a1 = par(a);
    long long int b1 = par(b);
    if (a1 == b1) {
      cnt++;
    } else {
      join(a1, b1);
    }
  }
  cout << cnt;
}
