#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
inline long long read() {
  long long x = 0, p = 1;
  char wa = getchar();
  while (!isdigit(wa)) {
    if (wa == '-') p = -1;
    wa = getchar();
  }
  while (isdigit(wa)) {
    x = x * 10 + wa - '0';
    wa = getchar();
  }
  return x * p;
}
int fa[maxn], m, n, ans;
int getf(int x) { return fa[x] = fa[x] == x ? x : getf(fa[x]); }
int main() {
  n = read();
  m = read();
  ans = 0;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int x, y, i = 1; i <= m; ++i) {
    x = read(), y = read();
    x = getf(x), y = getf(y);
    if (x == y)
      ++ans;
    else
      fa[y] = x;
  }
  printf("%d\n", ans);
  return 0;
}
