#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> f[N];
int n, m, x, y, sum, vis[N], ans;
void dfs(int i) {
  if (vis[i]) return;
  vis[i] = 1;
  for (int j = 0; j < f[i].size(); j++) dfs(f[i][j]);
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    f[x].push_back(y);
    f[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      dfs(i);
      ans++;
    }
  printf("%d", m + ans - n);
  return 0;
}
