#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
  num = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar();
  num *= f;
}
int power(int x, int k, int p) {
  int res = 1;
  for (; k; k >>= 1, x = 1ll * x * x % p)
    if (k & 1) res = 1ll * res * x % p;
  return res;
}
const int maxn = 1e5 + 5;
int n, m, tot, sumb, rt, pnt;
int head[maxn], des[maxn << 1], nxt[maxn << 1];
int cntb[maxn], sz[maxn], vis[maxn], dep[maxn], fa[maxn];
void adde(int x, int y) {
  des[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
void dfs(int x) {
  vis[x] = 1;
  cntb[x] = dep[x] & 1;
  sz[x] = 1;
  for (int(p) = head[(x)]; (p); (p) = nxt[(p)])
    if (des[p] != fa[x]) {
      if (des[p] == rt)
        pnt = x;
      else if (!vis[des[p]]) {
        dep[des[p]] = dep[x] + 1;
        fa[des[p]] = x;
        dfs(des[p]);
        cntb[x] += cntb[des[p]];
        sz[x] += sz[des[p]];
      }
    }
}
void dfs1(int x, int fa) {
  vis[x] = 1;
  for (int(p) = head[(x)]; (p); (p) = nxt[(p)])
    if (des[p] != fa) {
      if (vis[des[p]])
        rt = des[p];
      else
        dfs1(des[p], x);
    }
}
int main() {
  read(n);
  read(m);
  if (n & 1) return puts("-1"), 0;
  for (int(i) = (1); (i) <= (m); (i)++) {
    int x, y;
    read(x);
    read(y);
    adde(x, y);
    adde(y, x);
  }
  if (m == n - 1) {
    dep[1] = 1;
    dfs(1);
    if (cntb[1] * 2 != n)
      puts("-1");
    else {
      long long ans = 0;
      for (int(i) = (2); (i) <= (n); (i)++)
        ans += abs(sz[i] - cntb[i] - cntb[i]);
      cout << ans << endl;
    }
  } else {
    dfs1(1, 0);
    for (int(i) = (1); (i) <= (n); (i)++) vis[i] = 0;
    dep[rt] = 1;
    dfs(rt);
    if (!(dep[pnt] & 1)) {
      if (cntb[rt] * 2 != n)
        puts("-1");
      else {
        long long ans = 0;
        vector<double> q;
        q.push_back(0);
        for (int(i) = (1); (i) <= (n); (i)++) vis[i] = 0;
        for (int i = pnt; i != rt; i = fa[i])
          vis[i] = 1, q.push_back((2 * cntb[i] - sz[i]) / 2.0),
          q.push_back((2 * cntb[i] - sz[i]) / 2.0);
        for (int(i) = (1); (i) <= (n); (i)++)
          if (i != rt && !vis[i]) ans += abs(sz[i] - 2 * cntb[i]);
        sort((q).begin(), (q).end());
        int tmp1 = q[((q).size()) / 2], tmp2 = tmp1 + 1;
        double now1 = 0, now2 = 0;
        for (int(i) = (0); (i) < (((q).size())); (i)++)
          now1 += abs(tmp1 - q[i]), now2 += abs(tmp2 - q[i]);
        cout << ans + min(now1, now2) << endl;
      }
    } else {
      int k = n - 2 * cntb[rt];
      if (k & 1)
        puts("-1");
      else {
        long long ans = 0;
        k >>= 1;
        for (int(i) = (1); (i) <= (n); (i)++) vis[i] = 0;
        for (int i = pnt; i != rt; i = fa[i])
          vis[i] = 1, ans += abs(sz[i] - 2 * cntb[i] - k);
        for (int(i) = (1); (i) <= (n); (i)++)
          if (i != rt && !vis[i]) ans += abs(sz[i] - 2 * cntb[i]);
        cout << ans + k << endl;
      }
    }
  }
  return 0;
}
