#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[1000000];
bool v[1000000];
long long cnt, start, mn;
void clear_visited() {
  long long i;
  for (i = 1; i < 1000000; i++) {
    v[i] = false;
  }
}
void dfs(long long s) {
  v[s] = true;
  cnt++;
  for (auto i : adj[s]) {
    if (v[i] == false) dfs(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, n, k, a, b;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  clear_visited();
  mn = 0;
  for (i = 1; i <= n; i++) {
    if (v[i] == false) {
      cnt = 0;
      dfs(i);
      mn = mn + (cnt - 1);
    }
  }
  cout << k - mn << endl;
  return 0;
}
