#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct DSU {
  vector<int> p, sz;
  int n;
  DSU(int x) : n(x) {
    p.resize(n + 1);
    sz.resize(n + 1, 1);
    for (int j = 1; j <= n; j++) p[j] = j;
  }
  int par(int x) { return (x == p[x]) ? x : (p[x] = par(p[x])); }
  int merge(int u, int v) {
    u = par(u);
    v = par(v);
    if (u == v) return 0;
    if (sz[u] > sz[v]) swap(u, v);
    sz[v] += sz[u];
    p[u] = v;
    return 1;
  }
};
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  DSU dsu(n);
  int ans = 0;
  for (int j = 0; j < k; j++) {
    int x, y;
    cin >> x >> y;
    ans += 1 - dsu.merge(x, y);
  }
  cout << ans << endl;
  return 0;
}
