#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
int f[N];
int find(int k) {
  if (f[k] == k) return k;
  return f[k] = find(f[k]);
}
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a != b) f[b] = a;
}
int main() {
  int n = read(), k = read();
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= k; i++) {
    int a = read(), b = read();
    merge(a, b);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (f[i] == i) cnt++;
  printf("%d\n", k - (n - cnt));
  return 0;
}
