#include <bits/stdc++.h>
using namespace std;
class DisjointSet {
 public:
  vector<int> parent;
  DisjointSet(int n) : parent(n) {
    for (int i = 0; i < n; i++) parent[i] = i;
  }
  void join(int a, int b) { parent[find(b)] = find(a); }
  int find(int a) { return a == parent[a] ? a : parent[a] = find(parent[a]); }
  bool check(int a, int b) { return find(a) == find(b); }
};
int main() {
  int n, k;
  cin >> n >> k;
  DisjointSet ds(n + 1);
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    ds.join(a, b);
  }
  map<int, int> component_size;
  for (int i = 1; i <= n; ++i) {
    ++component_size[ds.find(i)];
  }
  int modificator = 0;
  for (auto p : component_size) {
    modificator -= p.second - 1;
  }
  cout << k + modificator;
  return 0;
}
