#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 100005;
vector<int> v[N];
int ans, sz[N], q[N], f[N], x, y, vis[N], dep[N];
void GG() {
  puts("-1");
  exit(0);
}
void dfs(int p, int fa) {
  vis[p] = 1;
  f[p] = fa;
  for (auto i : v[p])
    if (i != fa) {
      if (vis[i]) {
        x = p;
        y = i;
        continue;
      }
      dep[i] = dep[p] ^ 1;
      dfs(i, p);
      sz[p] += sz[i];
    }
  sz[p] = -(sz[p] - 1);
  ans += abs(sz[p]);
}
int lca(int x, int y) {
  static int v[N];
  memset(v, 0, sizeof(v));
  for (int i = x; i; i = f[i]) v[i] = 1;
  for (int i = y; i; i = f[i])
    if (v[i]) return i;
}
int main() {
  int n = read(), m = read();
  for (int i = (int)(1); i <= (int)(m); i++) {
    int s = read(), t = read();
    v[s].push_back(t);
    v[t].push_back(s);
  }
  dfs(1, 0);
  if (n & 1) GG();
  if (m + 1 == n) {
    if (sz[1]) GG();
    cout << ans << endl;
  } else {
    if (dep[x] == dep[y]) {
      int cn = sz[1] / 2;
      if (dep[x] == 0) cn = -cn;
      for (int i = x; i; i = f[i]) {
        ans -= abs(sz[i]);
        sz[i] += cn * (((dep[x] - dep[i]) & 1) ? -1 : 1);
        ans += abs(sz[i]);
      }
      for (int i = y; i; i = f[i]) {
        ans -= abs(sz[i]);
        sz[i] += cn * (((dep[y] - dep[i]) & 1) ? -1 : 1);
        ans += abs(sz[i]);
      }
      cout << ans << endl;
    } else {
      if (sz[1]) GG();
      int t = lca(x, y);
      for (int i = x; i != t; i = f[i]) {
        q[++*q] = (((dep[x] - dep[i]) & 1) ? -1 : 1) * sz[i];
        ans -= abs(sz[i]);
      }
      for (int i = y; i != t; i = f[i]) {
        q[++*q] = (((dep[y] - dep[i]) & 1) ? -1 : 1) * sz[i];
        ans -= abs(sz[i]);
      }
      sort(&q[1], &q[*q + 1]);
      q[++*q] = 0;
      int jj = q[(*q + 1) / 2];
      for (int j = (int)(1); j <= (int)(*q); j++) ans += abs(q[j] - jj);
      cout << ans << endl;
    }
  }
}
