#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class T>
inline void getc(T &x) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
         (c >= 'A' && c <= 'Z'));
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  x = c;
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::getc;
using io ::print;
using io ::putc;
using io ::rd;
const int MAXN = 1e5 + 5;
int n, m;
vector<int> g[MAXN];
namespace Tree {
int ans;
int dfs(int x, int ff, int col) {
  int res = col;
  for (auto &v : g[x]) {
    if (v == ff) continue;
    res += dfs(v, x, -col);
  }
  ans += abs(res);
  return res;
}
void solve() {
  ans = 0;
  if (dfs(1, 0, 1))
    puts("-1");
  else
    printf("%d\n", ans);
}
}  // namespace Tree
int col[MAXN], U, V;
void dfs(int x, int ff, int c) {
  col[x] = c;
  for (auto &v : g[x]) {
    if (v == ff) continue;
    if (!col[v])
      dfs(v, x, -c);
    else
      U = x, V = v;
  }
}
namespace No_Tree1 {
int Ans;
int dfs(int x, int ff) {
  int res = col[x];
  for (auto &v : g[x]) {
    if (v == ff || (U == x && V == v) || (U == v && V == x)) continue;
    res += dfs(v, x);
  }
  return res;
}
int rdfs(int x, int ff) {
  for (auto &v : g[x]) {
    if (v == ff || (U == x && V == v) || (U == v && V == x)) continue;
    col[x] += rdfs(v, x);
  }
  Ans += abs(col[x]);
  return col[x];
}
void solve() {
  Ans = dfs(1, 0);
  if (Ans % 2) {
    puts("-1");
    return;
  }
  col[U] -= Ans / 2;
  col[V] -= Ans / 2;
  Ans = abs(Ans / 2);
  rdfs(1, 0);
  printf("%d\n", Ans);
}
}  // namespace No_Tree1
namespace No_Tree2 {
int Ans, fa[MAXN];
void dfs(int x, int ff, int c) {
  col[x] = c;
  fa[x] = ff;
  for (auto &v : g[x]) {
    if (v == ff || (U == x && V == v) || (U == v && V == x)) continue;
    dfs(v, x, -c);
    col[x] += col[v];
  }
}
int st[MAXN], tp, del;
bool is[MAXN];
void solve() {
  dfs(1, 0, -1);
  if (col[1]) {
    puts("-1");
    return;
  }
  tp = 0;
  for (int i = 1; i <= n; i++) is[i] = 0;
  for (int i = U; i != V && i; i = fa[i]) st[++tp] = col[i], is[i] = 1;
  sort(st + 1, st + tp + 1);
  if (tp & 1)
    del = st[tp + 1 >> 1];
  else
    del = st[tp >> 1] + st[tp / 2 + 1] >> 1;
  Ans = abs(del);
  for (int i = 1; i <= n; i++)
    if (is[i])
      Ans += abs(col[i] - del);
    else
      Ans += abs(col[i]);
  printf("%d\n", Ans);
}
}  // namespace No_Tree2
int T;
int main() {
  T = 1;
  while (T--) {
    rd(n);
    rd(m);
    for (int i = 1; i <= n; i++) col[i] = 0, g[i].clear();
    for (int i = 1, x, y; i <= m; i++) {
      rd(x);
      rd(y);
      g[x].push_back(y);
      g[y].push_back(x);
    }
    if (n & 1) {
      puts("-1");
      continue;
    }
    if (m == n - 1) {
      Tree::solve();
      continue;
    }
    U = V = 0;
    dfs(1, 0, 1);
    if (col[U] == col[V])
      No_Tree1::solve();
    else
      No_Tree2::solve();
  }
  return 0;
}
