#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int64_t LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, k, ans = 0;
  cin >> k >> n;
  vector<vector<int>> edge(n + k);
  vector<int> vis(n + k);
  for (int i = 0, a, b; i < n; i++) {
    cin >> a >> b;
    a--, b--;
    edge[i].push_back(a + n);
    edge[a + n].push_back(i);
    edge[i].push_back(b + n);
    edge[b + n].push_back(i);
  }
  queue<int> bfs;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      bfs.push(i);
      while (!bfs.empty()) {
        int w = bfs.front();
        bfs.pop();
        bool ok = false;
        for (int &a : edge[w]) {
          if (vis[a]) continue;
          ok = true;
          vis[a] = 1;
          bfs.push(a);
        }
        if (w < n && ok) ans++;
      }
    }
  }
  cout << n - ans;
  return 0;
}
