#include <bits/stdc++.h>
using namespace std;
int t, n, m, x[100010], y[100010], f[100010], g[100010], r[100010], u, v, w, p,
    q;
vector<int> a[100010];
inline void dfs(int i, int j) {
  int k;
  for (k = 0; k < a[i].size(); k++)
    if (a[i][k] != j)
      if (!x[a[i][k]]) {
        x[a[i][k]] = -x[i];
        dfs(a[i][k], i);
      } else {
        u = i;
        v = a[i][k];
        w = (x[i] == x[a[i][k]]);
      }
}
inline void dp(int i, int j) {
  int k;
  f[i] = x[i];
  g[i] = y[i];
  for (k = 0; k < a[i].size(); k++)
    if (a[i][k] != j && (i != u || a[i][k] != v) && (i != v || a[i][k] != u)) {
      dp(a[i][k], i);
      f[i] += f[a[i][k]];
      g[i] += g[a[i][k]];
    }
}
int main() {
  int i, j, k;
  t = 1;
  while (t--) {
    scanf("%d%d", &n, &m);
    for (i = 1; i <= n; i++) a[i].clear();
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &j, &k);
      a[j].push_back(k);
      a[k].push_back(j);
    }
    if (n & 1) {
      printf("-1\n");
      continue;
    }
    for (i = 1; i <= n; i++) x[i] = y[i] = 0;
    p = q = 0;
    x[1] = 1;
    dfs(1, 0);
    if (m == n - 1) {
      dp(1, 0);
      if (f[1]) {
        printf("-1\n");
        continue;
      }
      for (i = 2; i <= n; i++) p += abs(f[i]);
      printf("%d\n", p);
    } else if (w) {
      dp(1, 0);
      if (f[1] & 1) {
        printf("-1\n");
        continue;
      }
      p = abs(f[1] / 2);
      x[u] -= f[1] / 2;
      x[v] -= f[1] / 2;
      dp(1, 0);
      for (i = 2; i <= n; i++) p += abs(f[i]);
      printf("%d\n", p);
    } else {
      y[u] = 1;
      y[v] = -1;
      dp(1, 0);
      q = 1;
      r[1] = 0;
      for (i = 1; i <= n; i++)
        if (g[i])
          r[++q] = f[i] * g[i];
        else
          p += f[i];
      sort(r + 1, r + q + 1);
      for (i = 1; i <= q; i++) p += abs(r[i] - r[q + 1 >> 1]);
      printf("%d\n", p);
    }
  }
  return 0;
}
