#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int p[N];
int find(int a) {
  if (p[a] != a) p[a] = find(p[a]);
  return p[a];
}
int main(void) {
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    int pa = find(a), pb = find(b);
    if (pa == pb)
      ans++;
    else
      p[pa] = pb;
  }
  cout << ans << endl;
  return 0;
}
