#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 4;
int fa[maxn];
int Find(int a) {
  if (a == fa[a])
    return a;
  else
    return fa[a] = Find(fa[a]);
}
pair<int, int> p[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i <= n; ++i) {
    fa[i] = i;
  }
  int x, y;
  for (int i = 0; i < k; ++i) {
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    p[i] = make_pair(x, y);
  }
  sort(p, p + k);
  int N = unique(p, p + k) - p;
  set<int> s;
  for (int i = 0; i < N; ++i) {
    x = p[i].first;
    y = p[i].second;
    s.insert(x);
    s.insert(y);
    int fx = Find(x), fy = Find(y);
    if (fx != fy) fa[fx] = fy;
  }
  int ans = n;
  for (int i = 1; i <= n; ++i) {
    if (fa[i] == i) ans--;
  }
  cout << k - ans << endl;
}
