#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const long long mod = 998244353;
int pre[maxn];
int find(int x) { return x == pre[x] ? pre[x] : pre[x] = find(pre[x]); }
int main() {
  int n, m, res = 0, u, v;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    u = find(u);
    v = find(v);
    if (u != v) {
      pre[u] = v;
      res++;
    }
  }
  printf("%d\n", m - res);
  return 0;
}
