#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int pl = 1e6;
double rast(int x1, int y1, int x2, int y2) {
  return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int p[100005];
int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
void unite(int x, int y) {
  x = get(x);
  y = get(y);
  if (x != y) p[x] = y;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  iota(p, p + n, 0);
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    unite(x, y);
  }
  vector<int> cl(n);
  for (int i = 0; i < n; i++) cl[get(i)]++;
  int ng = 0, clg = 0;
  for (int i = 0; i < n; i++)
    if (cl[i] > 1) {
      ng++;
      clg += cl[i];
    }
  cout << k - clg + ng;
}
