#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, dep[100100], w[100100], a[100100], tot;
long long ans;
struct edge {
  int v;
  edge *nxt;
} pool[200100], *tp = pool, *fst[100100];
int getint() {
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return x;
}
void dfs1(int x, int fa) {
  dep[x] = dep[fa] + 1, w[x] = -w[fa];
  for (edge *i = fst[x]; i; i = i->nxt)
    if (i->v != fa)
      if (dep[i->v])
        u = x, v = i->v;
      else
        dfs1(i->v, x);
}
bool dfs2(int x, int fa) {
  bool flag = x == u || x == v;
  for (edge *i = fst[x]; i; i = i->nxt)
    if (dep[i->v] > dep[x]) flag ^= dfs2(i->v, x), w[x] += w[i->v];
  if (flag)
    a[++tot] = w[x];
  else
    ans += abs(w[x]);
  return flag;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    u = getint(), v = getint();
    *tp = (edge){v, fst[u]}, fst[u] = tp++;
    *tp = (edge){u, fst[v]}, fst[v] = tp++;
  }
  if (n & 1) {
    puts("-1");
    return 0;
  }
  w[0] = 1, dfs1(1, 0);
  if (m > n && !((dep[u] - dep[v]) & 1)) {
    int sum = 0;
    for (int i = 1; i <= n; ++i) sum += w[i];
    w[u] += sum / 2, w[v] += ans = sum / 2, u = v = 0, dfs2(1, 0);
  }
  tot = 1, dfs2(1, 0), nth_element(a + 1, a + tot / 2, a + 1 + tot);
  for (int i = 1; i <= tot; ++i) ans += abs(a[i] - a[tot / 2]);
  printf("%lld\n", ans);
  return 0;
}
