#include <bits/stdc++.h>
namespace BoDaJingShen {
int abs(int x) { return x < 0 ? -x : x; }
const int N = 100100, M = N * 2;
struct disjoint_set_union {
  int q[N];
  void init(int n) {
    for (int i = 1; i <= n; i++) q[i] = i;
  }
  int ask(int p) { return p == q[p] ? p : q[p] = ask(q[p]); }
  inline void link(int u, int v) { q[ask(u)] = ask(v); }
  inline bool uni(int u, int v) { return ask(u) == ask(v); }
} d;
int begin[N], next[M], to[M];
int dep[N], s[N];
int n, m, e, ans, sx, sy;
void add(int x, int y, bool k = 1) {
  to[++e] = y;
  next[e] = begin[x];
  begin[x] = e;
  if (k) add(y, x, 0);
}
void predfs(int p, int h = 0) {
  for (int i = begin[p], q; i; i = next[i])
    if ((q = to[i]) != h) dep[q] = dep[p] + 1, predfs(q, p);
}
int dfs(int p, int h = 0) {
  int ret = s[p];
  for (int i = begin[p], q; i; i = next[i])
    if ((q = to[i]) != h) dep[q] = dep[p] + 1, ret += dfs(q, p);
  ans += abs(ret);
  return ret;
}
void initialize() {
  scanf("%d%d", &n, &m);
  d.init(n);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    if (d.uni(u, v))
      sx = u, sy = v;
    else
      add(u, v), d.link(u, v);
  }
  predfs(1);
}
void work0() { printf("?\n"); }
void work1() {
  int tmp = 0, f;
  for (int i = 1; i <= n; i++) tmp += (s[i] = (dep[i] & 1) ? 1 : -1);
  if (tmp & 1) {
    printf("-1\n");
    return;
  }
  ans = abs(tmp / 2);
  f = tmp > 0 ? -1 : 1;
  s[sx] += f * ans;
  s[sy] += f * ans;
  if (dfs(1)) printf("fuck\n");
  printf("%d\n", ans);
}
void solve() {
  initialize();
  if (m == n - 1) {
    ans = 0;
    for (int i = 1; i <= n; i++) s[i] = (dep[i] & 1) ? 1 : -1;
    if (dfs(1) == 0)
      printf("%d\n", ans);
    else
      printf("-1\n");
  } else {
    if ((dep[sx] & 1) == (dep[sy] & 1))
      work1();
    else
      work0();
  }
}
}  // namespace BoDaJingShen
int main() {
  BoDaJingShen::solve();
  return 0;
}
