#include <bits/stdc++.h>
using namespace std;
inline int getint() {
  static char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  int res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res;
}
template <class T>
inline void tense(T &a, const T &b) {
  if (b < a) a = b;
}
const int MaxN = 100000;
const int MaxM = 100000;
const int INF = 0x3f3f3f3f;
int n, m;
struct halfEdge {
  int v, w;
  halfEdge *next;
};
halfEdge adj_pool[MaxM * 2], *adj_tail = adj_pool;
halfEdge *adj[MaxN + 1];
inline void addEdge(const int &u, const int &v, const int &w) {
  adj_tail->v = v, adj_tail->w = w;
  adj_tail->next = adj[u], adj[u] = adj_tail++;
}
inline halfEdge *oppo(const halfEdge *e) {
  return adj_pool + ((e - adj_pool) ^ 1);
}
int f[MaxN + 1][2];
void dfs(const int &u, const int &prev) {
  f[u][0] = 0;
  f[u][1] = INF;
  for (halfEdge *e = adj[u]; e; e = e->next)
    if (e->w && e->v != prev) {
      dfs(e->v, u);
      int p = f[u][0], q = f[u][1];
      f[u][0] = min(q + f[e->v][0] + 1, p + f[e->v][1]);
      f[u][1] = min(p + f[e->v][0] + 1, q + f[e->v][1]);
    }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u = getint(), v = getint();
    addEdge(u, v, 1);
    addEdge(v, u, 1);
  }
  if (m == n - 1) {
    dfs(1, 0);
    cout << (f[1][1] < INF ? f[1][1] : -1);
    cout << endl;
  }
  return 0;
}
