#include <bits/stdc++.h>

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};


int main()
{
  int N, M;
  int S[3000], G[3000];

  cin >> N >> M;
  UnionFind tree(N);
  for(int i = 0; i < M; i++) {
    cin >> S[i] >> G[i];
    tree.unite(--S[i], --G[i]);
  }

  int sum[3000] = {};
  for(int i = 0; i < M; i++) {
    ++sum[tree.find(S[i])];
  }

  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(tree.find(i) != i) continue;
    ret += 1 + sum[i] - tree.size(i);
  }
  cout << ret << endl;
}