#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10;
long long n, q, m, k;
string s;
set<pair<long long, long long> > a;
long long x, y;
long long check[MAXN], flavor[MAXN];
long long goc[MAXN];
long long timgoc(long long x) {
  if (goc[x] < 0) return x;
  goc[x] = timgoc(goc[x]);
  return goc[x];
}
void hopgoc(long long x, long long y) {
  x = timgoc(x);
  y = timgoc(y);
  if (goc[x] >= goc[y]) {
    goc[y] += goc[x];
    goc[x] = y;
  } else {
    goc[x] += goc[y];
    goc[y] = x;
  }
}
long long cnt;
signed main() {
  cin >> m >> n;
  for (long long i = 1; i <= m; i++) goc[i] = -1;
  long long realcnt = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;
    if (a.find({x, y}) != a.end()) {
      cnt++;
    } else {
      a.insert({x, y});
      a.insert({y, x});
      realcnt++;
    }
  }
  long long tmp = 0;
  set<pair<long long, long long> >::iterator itr;
  for (itr = a.begin(); itr != a.end(); itr++) {
    pair<long long, long long> zz = *itr;
    if (timgoc(zz.first) != timgoc(zz.second)) {
      hopgoc(zz.first, zz.second);
    } else {
      tmp++;
    }
  }
  tmp -= realcnt;
  tmp += cnt;
  cout << tmp;
}
