#include <bits/stdc++.h>
using namespace std;
long long int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
}
long long int par[200005];
long long int find_par(long long int node) {
  if (par[node] == node)
    return node;
  else
    return par[node] = find_par(par[node]);
}
bool union_set(long long int a, long long int b) {
  long long int par_a = find_par(a);
  long long int par_b = find_par(b);
  if (par_a == par_b)
    return false;
  else {
    par[par_b] = par_a;
    return true;
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) par[i] = i;
  long long int ans = 0;
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    if (!union_set(x, y)) ans++;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
