#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > graph;
vector<bool> vis;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 9;
void dfs(int node) {
  vis[node] = true;
  for (auto &child : graph[node]) {
    if (!vis[child]) {
      dfs(child);
    }
  }
}
void test_case(int tc) {
  int n, m;
  cin >> n >> m;
  graph = vector<vector<int> >(n + 1);
  vis = vector<bool>(n + 1, 0);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int c = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
      c++;
    }
  }
  cout << m - n + c << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  for (int tc = 1; tc <= t; ++tc) test_case(tc);
}
