#include <bits/stdc++.h>
template <class T>
__inline__ __attribute__((always_inline)) bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}
template <class T>
__inline__ __attribute__((always_inline)) bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}
template <class T>
__inline__ __attribute__((always_inline)) T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}
template <class T>
__inline__ __attribute__((always_inline)) T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}
template <class T>
__inline__ __attribute__((always_inline)) T myabs(const T &a) {
  return a > 0 ? a : -a;
}
const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);
const int MAXN = 100000 + 5;
struct Tree {
  int hed[MAXN], nxt[MAXN * 2], to[MAXN * 2], fa[MAXN], f[MAXN][2], cnt;
  void addEdge(int u, int v) {
    ++cnt;
    to[cnt] = v;
    nxt[cnt] = hed[u];
    hed[u] = cnt;
  }
  void DFS(int u) {
    f[u][1] = INF;
    for (int e = hed[u]; e; e = nxt[e]) {
      int v = to[e];
      if (v != fa[u]) {
        fa[v] = u;
        DFS(v);
        int x = f[u][0], y = f[u][1];
        f[u][0] = mymin(x + f[v][1], y + f[v][0] + 1);
        chkmin(f[u][0], INF);
        f[u][1] = mymin(y + f[v][1], x + f[v][0] + 1);
        chkmin(f[u][1], INF);
      }
    }
  }
} T;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n > m) {
    for (int i = 1, iend = m; i <= iend; ++i) {
      int u, v;
      scanf("%d%d", &u, &v);
      T.addEdge(u, v);
      T.addEdge(v, u);
    }
    T.DFS(1);
    printf("%d\n", T.f[1][1] >= INF ? -1 : T.f[1][1]);
  }
  return 0;
}
