#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF_of_int = 1e9;
int n, m, deg[N], vis[N];
int dp[N][2], qu[N], tp = 0;
vector<int> g[N];
void update(int u, int v) {
  int u0 = dp[u][0], u1 = dp[u][1];
  dp[u][0] = min(u0 + dp[v][1], u1 + dp[v][0] + 1);
  dp[u][1] = min(u1 + dp[v][1], u0 + dp[v][0] + 1);
}
void dfs(int u, int fa) {
  vis[u] = 1;
  qu[++tp] = u;
  for (auto v : g[u]) {
    if (!vis[v]) {
      dfs(v, u);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    dp[i][0] = 0;
    dp[i][1] = INF_of_int;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      q.push(i);
    }
  }
  int las = 0;
  while (q.size()) {
    int u = q.front();
    las = u;
    q.pop();
    vis[u] = 1;
    for (auto v : g[u]) {
      if (!vis[v]) {
        update(v, u);
        if ((--deg[v]) == 1) {
          q.push(v);
        }
      }
    }
  }
  if (n > m) {
    if (dp[las][1] >= INF_of_int) {
      dp[las][1] = -1;
    }
    printf("%d\n", dp[las][1]);
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, 0);
      break;
    }
  }
  int res00 = min(INF_of_int, dp[qu[1]][0] + dp[qu[2]][0]);
  int res01 = min(INF_of_int, dp[qu[1]][0] + dp[qu[2]][1]);
  int res10 = min(INF_of_int, dp[qu[1]][1] + dp[qu[2]][0]);
  int res11 = min(INF_of_int, dp[qu[1]][1] + dp[qu[2]][1]);
  for (int i = 3; i <= tp; i++) {
    int las00 = res00, las01 = res01, las10 = res10, las11 = res11;
    res00 =
        min(INF_of_int, min(las00 + dp[qu[i]][1] + 1, las01 + dp[qu[i]][0]));
    res01 =
        min(INF_of_int, min(las00 + dp[qu[i]][0] + 1, las01 + dp[qu[i]][1]));
    res10 =
        min(INF_of_int, min(las10 + dp[qu[i]][1] + 1, las11 + dp[qu[i]][0]));
    res11 =
        min(INF_of_int, min(las10 + dp[qu[i]][0] + 1, las11 + dp[qu[i]][1]));
  }
  printf("%d\n", min(res11, res00 + 1));
  return 0;
}
