#include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
int n, m, sum;
int head[MAXN];
struct Edge {
  int link, to;
} e[MAXN << 1];
inline void add(int u, int v) { e[++sum] = (Edge){v, head[u]}, head[u] = sum; }
namespace Tree {
int del[MAXN];
void dfs(int u, int fa, int D) {
  del[u] = D % 2 == 1 ? 1 : -1;
  for (int i = head[u]; i; i = e[i].to) {
    int v = e[i].link;
    if (v == fa) continue;
    dfs(v, u, D + 1), del[u] += del[v];
  }
}
inline void gao() {
  dfs(1, 0, 1);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans += abs(del[i]);
  if (del[1])
    puts("-1");
  else
    printf("%lld\n", ans);
}
};  // namespace Tree
namespace GayRingTree {
int S, T, cnt;
bool flg;
int dep[MAXN], del[MAXN], f[MAXN], b[MAXN];
bool vis[MAXN];
void dfs(int u, int fa) {
  vis[u] = true, dep[u] = dep[fa] + 1, f[u] = fa;
  del[u] = dep[u] % 2 == 1 ? 1 : -1;
  for (int i = head[u]; i; i = e[i].to) {
    int v = e[i].link;
    if (vis[v] && v != fa) S = u, T = v;
    if (vis[v] || v == fa) continue;
    dfs(v, u), del[u] += del[v];
  }
}
inline void gao() {
  assert(0);
  dfs(1, 0), flg = (dep[S] + dep[T] + 1) % 2;
  int L = S, R = T, lca;
  while (L != R) {
    if (dep[L] > dep[R])
      L = f[L];
    else
      R = f[R];
  }
  lca = L;
  if (flg) {
    if (abs(del[1]) % 2 == 1) return puts("-1"), void();
    int hhz = del[1] / 2;
    del[lca] -= hhz;
    for (int i = S; i != lca; i = f[i]) del[i] -= hhz;
    for (int i = T; i != lca; i = f[i]) del[i] -= hhz;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) ans += abs(del[i]);
    printf("%lld\n", ans);
  } else {
    assert(0);
    if (del[1]) return puts("-1"), void();
    b[++cnt] = del[lca];
    for (int i = S; i != lca; i = f[i]) b[++cnt] = del[i];
    for (int i = T; i != lca; i = f[i]) b[++cnt] = del[i];
    std::sort(b + 1, b + cnt + 1);
    int QAQ = b[(cnt + 1) / 2];
    del[lca] -= QAQ;
    for (int i = S; i != lca; i = f[i]) del[i] -= QAQ;
    for (int i = T; i != lca; i = f[i]) del[i] -= QAQ;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) ans += abs(del[i]);
    printf("%lld\n", ans);
  }
}
};  // namespace GayRingTree
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; ++i)
    scanf("%d%d", &u, &v), add(u, v), add(v, u);
  if (n % 2 == 1) return puts("-1"), 0;
  if (m < n)
    Tree::gao();
  else
    GayRingTree::gao();
  return 0;
}
