#include <bits/stdc++.h>
using namespace std;
int a, b, n, m, parent[100005], ans;
int findpar(int x) {
  if (parent[x] != x) parent[x] = findpar(parent[x]);
  return parent[x];
}
bool disjoint(int x, int y) {
  x = findpar(x);
  y = findpar(y);
  if (x == y)
    return false;
  else {
    parent[y] = x;
    return true;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) parent[i] = i;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (!disjoint(a, b)) ans++;
  }
  cout << ans << endl;
}
