#include <bits/stdc++.h>
using namespace std;
int n, m, cnt[2], stk[101000], top, d[101000], cX, cY, len, sum;
vector<int> g[101000];
bool col[101000], vc[101000];
long long ans;
void paint(int x, int fa) {
  d[x] += col[x] ? +1 : -1;
  for (int v : g[x])
    if (v != fa) col[v] = col[x] ^ 1, paint(v, x);
}
void del_vec(vector<int> &a, int e) {
  for (auto it = a.begin(); it != a.end(); ++it)
    if (*it == e) {
      a.erase(it);
      return;
    }
}
void find_cycle(int x, int fa) {
  vc[x] = true;
  stk[++top] = x;
  int del = -1;
  for (int v : g[x])
    if (v != fa) {
      if (!vc[v])
        find_cycle(v, x);
      else if (!cX) {
        cX = x, cY = v;
        for (len = 0; stk[top - len] != v; ++len)
          ;
        ++len;
        del = v;
      } else
        del = v;
    }
  if (del != -1) del_vec(g[x], del);
  --top;
}
int dfs(int x, int fa) {
  int sum = d[x];
  for (int v : g[x])
    if (v != fa) sum += dfs(v, x);
  ans += abs(sum);
  return sum;
}
long long solve(int dX, int dY) {
  for (int i = 1; i <= n; ++i) d[i] = 0;
  paint(1, 0);
  d[cX] += dX, d[cY] += dY;
  ans = 0;
  sum = dfs(1, 0);
  return sum != 0 ? -1 : ans;
}
long long F(int x) { return solve(x, -x) + abs(x); }
int main() {
  scanf("%d%d", &n, &m);
  if (n % 2 != 0) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y), g[y].push_back(x);
  }
  if (m == n - 1)
    printf("%d\n", solve(0, 0));
  else {
    find_cycle(1, 0);
    if (len % 2 == 0) {
      if (solve(0, 0) == -1)
        puts("-1");
      else {
        int l = 0, r = 2 * n;
        for (; l < r - 3;) {
          int _l = (l * 2 + r) / 3, _r = (l + r * 2) / 3;
          if (F(_l - n) < F(_r - n))
            r = _r;
          else
            l = _l;
        }
        long long mn = F(l - n);
        for (int i = l + 1; i <= r; ++i) {
          long long tmp = F(i - n);
          if (tmp < mn) mn = tmp, l = i;
        }
        printf("%lld\n", mn);
      }
    } else {
      long long tmp = solve(0, 0);
      int s = sum;
      printf("%lld\n", tmp != -1 ? tmp : (solve(-s / 2, -s / 2) + abs(s) / 2));
    }
  }
  return 0;
}
