#include <bits/stdc++.h>
using namespace std;
long long n, ans, u, v, i, root_u, root_v, arr[100001], len[100001], c[100001],
    k;
vector<pair<long long, long long> > in;
long long find(long long x) {
  if (arr[x] == x) return x;
  return arr[x] = find(arr[x]);
}
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) arr[i] = i, len[i] = 1;
  for (i = 0; i < k; i++) {
    cin >> u >> v;
    root_u = find(u);
    root_v = find(v);
    if (root_u != root_v) arr[root_u] = root_v, len[root_v] += len[root_u];
    c[u]++;
  }
  for (i = 1; i <= n; i++)
    if (arr[i] != i) c[find(i)] += c[i];
  for (i = 1; i <= n; i++)
    if (arr[i] == i) ans += (c[i] - len[i] + 1);
  cout << ans;
  return 0;
}
