#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T &x, const T &y) {
  return x < y ? x : y;
}
template <typename T>
inline T qmax(const T &x, const T &y) {
  return x > y ? x : y;
}
template <typename T>
inline void getmin(T &x, const T &y) {
  if (y < x) x = y;
}
template <typename T>
inline void getmax(T &x, const T &y) {
  if (y > x) x = y;
}
inline void fileio(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int N = 1e5 + 7, M = N << 1;
int v[M], nxt[M];
int head[N], dep[N];
int n, m;
inline void addedge(int p, int x, int y) {
  v[p] = y, nxt[p] = head[x], head[x] = p;
}
namespace task1 {
long long ans = 0;
inline int dfs(int u, int p) {
  dep[u] = dep[p] + 1;
  int rest = (dep[u] & 1 ? 1 : -1);
  for (int e = head[u]; e; e = nxt[e]) {
    if (v[e] == p) continue;
    rest += dfs(v[e], u);
  }
  ans += abs(rest);
  return rest;
}
inline int solve() {
  if (dfs(1, 0)) return puts("-1"), 0;
  printf("%lld\n", ans);
  return 0;
}
}  // namespace task1
namespace task2 {
bool vis[N], used[M];
int stk[N], top;
long long val[N], ans = 0;
int len;
vector<int> node;
inline bool init(int u) {
  vis[u] = true;
  stk[++top] = u;
  for (int e = head[u]; e; e = nxt[e]) {
    if (used[e >> 1]) continue;
    used[e >> 1] = true;
    if (vis[v[e]]) {
      while (stk[top] != v[e]) node.push_back(stk[top--]);
      node.push_back(v[e]);
      return true;
    } else {
      if (init(v[e])) return true;
    }
  }
  --top;
  return false;
}
inline int dfs(int u, int c) {
  vis[u] = true;
  int rest = (c ? 1 : -1);
  for (int e = head[u]; e; e = nxt[e]) {
    if (vis[v[e]]) continue;
    rest += dfs(v[e], c ^ 1);
  }
  ans += abs(rest);
  return rest;
}
inline long long calc(long long sum) {
  long long res = 0;
  for (register int i = 0; i < (len); ++i) res += abs(sum += val[i]);
  return res;
}
inline int solve() {
  init(1);
  len = node.size();
  memset(vis + 1, 0, sizeof(bool) * n);
  for (register int i = 0; i < (len); ++i) vis[node[i]] = true;
  long long tot = 0;
  for (register int i = 0; i < (len); ++i) {
    val[i] = dfs(node[i], i & 1);
    ans -= abs(val[i]);
    tot += val[i];
  }
  if (len & 1) {
    tot >>= 1;
    val[0] -= tot;
    val[len - 1] -= tot;
    printf("%lld\n", ans + calc(0) + tot);
  } else {
    if (tot) return puts("-1"), 0;
    int ul = -n - 1, ur = n + 1;
    while (ur - ul > 3) {
      int m1 = (2 * ul + ur) / 3, m2 = (ul + 2 * ur) / 3;
      if (calc(m1) < calc(m2))
        ur = m2;
      else
        ul = m1;
    }
    long long res = calc(ul);
    for (register int i = (ul + 1); i <= (ur); ++i) getmin(res, calc(i));
    printf("%lld\n", ans + res);
  }
  return 0;
}
}  // namespace task2
int main() {
  scanf("%d%d", &n, &m);
  if (n & 1) return puts("-1"), 0;
  for (register int i = (1); i <= (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(((i) << 1), x, y);
    addedge(((i) << 1 ^ 1), y, x);
  }
  if (m == n - 1)
    task1::solve();
  else
    task2::solve();
  return 0;
}
