#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
inline int read() {
  int x = 0, f = 1;
  char C = getchar();
  while (!isdigit(C)) {
    if (C == '-') f = -1;
    C = getchar();
  }
  while (isdigit(C)) x = (x << 1) + (x << 3) + C - '0', C = getchar();
  return x * f;
}
int n, m, fa[maxn], tot;
inline int find(int x) { return (x == fa[x]) ? x : fa[x] = find(fa[x]); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    int fx = find(x), fy = find(y);
    if (fx != fy)
      fa[fx] = fy;
    else
      tot++;
  }
  printf("%d\n", tot);
  return 0;
}
