#include <bits/stdc++.h>
using namespace std;
vector<long> adj[300005];
long long p;
long long int vis[300005];
void initialize() {
  for (long long i = 1; i < 300005; i++) {
    vis[i] = 0;
  }
}
void dfs(long long node) {
  p++;
  vis[node] = 1;
  for (long long i = 0; i < adj[node].size(); i++) {
    if (!vis[adj[node][i]]) {
      dfs(adj[node][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, j, l = 0, q = 0, r = 0, i, flag = 0, d, t, k;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  initialize();
  for (long long i = 1; i < n + 1; i++) {
    if (!vis[i]) {
      p = 0;
      dfs(i);
      q += p - 1;
    }
  }
  cout << k - q;
  return 0;
}
