#include <bits/stdc++.h>
using namespace std;
const int64_t M = 1000000007;
int64_t rt[100001];
int64_t sz[100001];
int64_t get(int64_t i) {
  while (rt[i] != i) {
    rt[i] = rt[rt[i]];
    i = rt[i];
  }
  return i;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int64_t n, k, u, v, ans;
  cin >> n >> k;
  for (int64_t i = 1; i <= n; i++) {
    sz[i] = 1;
    rt[i] = i;
  }
  ans = k;
  while (k--) {
    int64_t u, v;
    cin >> u >> v;
    u = get(u);
    v = get(v);
    if (u == v) continue;
    if (sz[v] > sz[u]) swap(u, v);
    rt[v] = rt[u];
    sz[u] += sz[v];
    ans--;
  }
  cout << ans << "\n";
}
