#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const int N = 1e5 + 10;
int x[N];
int y[N];
vector<int> cnt[N];
bool used[N];
void dfs(int v) {
  if (!used[x[v]]) {
    used[x[v]] = true;
    for (int i : cnt[x[v]]) dfs(i);
  }
  if (!used[y[v]]) {
    used[y[v]] = true;
    for (int i : cnt[y[v]]) dfs(i);
  }
}
signed main() {
  fast();
  int n, k;
  cin >> k >> n;
  int answ = 0;
  set<int> se;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    cnt[x[i]].push_back(i);
    cnt[y[i]].push_back(i);
    se.insert(x[i]);
    se.insert(y[i]);
  }
  answ = se.size();
  for (int i = 0; i < n; i++) {
    if (!used[x[i]]) {
      dfs(i);
      answ--;
    }
  }
  cout << max(0, n - answ);
  return 0;
}
