#include <bits/stdc++.h>
using namespace std;
int n, m, mark[((int)2100)], ans;
vector<int> e1[((int)2100)], e2[((int)2100)];
vector<pair<int, int> > ed;
stack<int> tpl;
int cnt, num[((int)2100)], comp, num_;
vector<int> e[((int)2100)], leaf;
void dfs1(int x, int par = 0) {
  mark[x] = 1;
  for (auto u : e1[x]) {
    if (u == par || mark[u] == 2) continue;
    e2[u].push_back(x);
    if (!mark[u]) dfs1(u, x);
  }
  mark[x] = 2;
  tpl.push(x);
}
void dfs2(int x) {
  mark[x] = 1;
  num[x] = cnt;
  for (auto u : e2[x])
    if (!mark[u]) dfs2(u);
}
int par[((int)14)][((int)2100)], sum[((int)14)][((int)2100)], dis[((int)2100)];
void pre_dfs(int x) {
  mark[x] = 1;
  num_++;
  if (e[x].size() == 1) leaf.push_back(x);
  for (int i = 1; i < ((int)14); i++)
    par[i][x] = par[i - 1][par[i - 1][x]],
    sum[i][x] = sum[i - 1][par[i - 1][x]] + sum[i - 1][x];
  for (auto u : e[x])
    if (u != par[0][x]) {
      par[0][u] = x;
      sum[0][u] = e[x].size();
      dis[u] = dis[x] + 1;
      pre_dfs(u);
    }
}
int iPar(int x, int num) {
  for (int i = 0; i < ((int)14); i++)
    if ((num & (1 << i))) x = par[i][x];
  return x;
}
int iSum(int x, int num) {
  int res = 0;
  for (int i = 0; i < ((int)14); i++)
    if ((num & (1 << i))) res += sum[i][x], x = par[i][x];
  return res;
}
int lca(int x, int y) {
  if (dis[x] < dis[y]) swap(x, y);
  x = iPar(x, dis[x] - dis[y]);
  if (x == y) return x;
  for (int i = ((int)14) - 1; i >= 0; i--)
    if (par[i][x] != par[i][y]) x = par[i][x], y = par[i][y];
  return par[0][x];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    e1[v].push_back(u);
    e1[u].push_back(v);
    ed.push_back({v, u});
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) dfs1(i);
  memset(mark, 0, sizeof mark);
  while (tpl.size()) {
    int x = tpl.top();
    tpl.pop();
    if (mark[x]) continue;
    cnt++;
    dfs2(x);
  }
  ans = n - cnt;
  for (auto u : ed) {
    int x = num[u.first], y = num[u.second];
    if (x != y) e[x].push_back(y), e[y].push_back(x);
  }
  memset(mark, 0, sizeof mark);
  for (int i = 1; i <= cnt; i++)
    if (!mark[i]) {
      int res = (int)1e9;
      num_ = 0;
      leaf.clear();
      comp++;
      pre_dfs(i);
      for (int p = 0; p < leaf.size(); p++)
        for (int q = p + 1; q < leaf.size(); q++) {
          int x = leaf[p], y = leaf[q], p = lca(x, y), all = num_ - leaf.size();
          int d = -2 * dis[p] + dis[x] + dis[y];
          res = min(res, all - d + 1);
        }
      if (res != (int)1e9) ans += res;
    }
  ans += comp - 1;
  cout << ans;
  return 0;
}
