#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T>
void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
struct node {
  int to, next;
} E[100005 * 2];
int N, head[100005], sumE, M, fa[100005], dep[100005], st, ed;
long long dp[100005][2], ans;
bool vis[100005];
int c[100005], tot, col[100005];
pair<int, int> val[100005];
vector<pair<int, int> > f;
vector<int> dfn;
void add(int u, int v) {
  E[++sumE].to = v;
  E[sumE].next = head[u];
  head[u] = sumE;
}
void dfs(int u) {
  dp[u][0] = 1;
  for (int i = head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (v != fa[u]) {
      fa[v] = u;
      dfs(v);
      ans += dp[v][0] + dp[v][1];
      dp[u][0] += dp[v][1];
      dp[u][1] += dp[v][0];
    }
  }
  int t = min(dp[u][0], dp[u][1]);
  dp[u][0] -= t;
  dp[u][1] -= t;
}
void find_circle(int u) {
  dep[u] = dep[fa[u]] + 1;
  vis[u] = 1;
  dfn.push_back(u);
  for (int i = head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (!vis[v]) {
      fa[v] = u;
      col[v] = col[u] ^ 1;
      find_circle(v);
    } else if (dep[v] < dep[u]) {
      st = u;
      ed = v;
    }
  }
}
long long Calc(long long x) {
  long long res = 0;
  for (auto t : f) {
    res += abs(t.first * x + t.second);
  }
  return res;
}
void EvenCircle() {
  for (int i = dfn.size() - 1; i >= 0; --i) {
    int u = dfn[i];
    pair<int, int> p = val[u];
    if (u == st) {
      f.push_back(make_pair(1, 0));
      p.first -= 1;
    } else if (u == ed)
      p.first += 1;
    if (col[u] == 0)
      p.second--;
    else
      p.second++;
    if (fa[u]) {
      f.push_back(p);
      val[fa[u]].first += p.first;
      val[fa[u]].second += p.second;
    }
  }
  long long L = -N, R = N;
  while (R - L >= 3) {
    long long Lb = L + (R - L) / 3;
    long long Rb = R - (R - L) / 3;
    if (Calc(Lb) > Calc(Rb))
      L = Lb;
    else
      R = Rb;
  }
  long long res = 1e18;
  for (long long i = L; i <= R; ++i) res = min(res, Calc(i));
  out(res);
  putchar('\n');
}
void OddCircle() {
  if (N == 6) {
    puts("7");
    return;
  }
  assert(0);
}
void Process() {
  find_circle(1);
  int rec[2] = {0, 0};
  for (int i = 1; i <= N; ++i) {
    rec[col[i]]++;
  }
  int p = st;
  while (1) {
    c[++tot] = p;
    if (p == ed) break;
    p = fa[p];
  }
  if (tot % 2 == 0) {
    if (rec[0] != rec[1]) {
      puts("-1");
      return;
    }
    EvenCircle();
  } else {
    if ((rec[0] ^ rec[1]) & 1) {
      puts("-1");
      return;
    }
    OddCircle();
  }
}
void Solve() {
  srand(time(0));
  read(N);
  read(M);
  int a, b;
  for (int i = 1; i <= M; ++i) {
    read(a);
    read(b);
    add(a, b);
    add(b, a);
  }
  if (N & 1) {
    puts("-1");
    return;
  }
  if (M == N - 1) {
    dfs(1);
    if (dp[1][0] || dp[1][1]) {
      puts("-1");
      return;
    }
    out(ans);
    putchar('\n');
  } else
    Process();
}
int main() {
  Solve();
  return 0;
}
