#include <bits/stdc++.h>
inline int gi() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int f[100010];
int fir[100010], dis[200010], nxt[200010], id;
inline void link(int a, int b) { nxt[++id] = fir[a], fir[a] = id, dis[id] = b; }
int ans = 0;
inline void dfs(int x, int fa = -1, int fa2 = -1) {
  f[x] = 1;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (fa == dis[i]) continue;
    if (fa2 == dis[i]) continue;
    dfs(dis[i], x);
    f[x] -= f[dis[i]];
  }
}
int stk[100010], tp;
int ins[100010];
int cir[200010], p;
inline void pre_dfs(int x, int lst = -1) {
  stk[++tp] = x;
  ins[x] = tp;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (lst == dis[i]) continue;
    if (ins[dis[i]]) {
      for (int j = ins[dis[i]]; j <= ins[x]; ++j) cir[++p] = stk[j];
      return;
    }
    pre_dfs(dis[i], x);
    if (p) return;
  }
  --tp;
  ins[x] = 0;
}
namespace flow {
int S, T, fir[100010], head[100010], dis[20000010], nxt[20000010], w[20000010],
    cost[20000010], id = 1;
inline void link(int a, int b, int c, int d) {
  nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c, cost[id] = d;
  nxt[++id] = fir[b], fir[b] = id, dis[id] = a, w[id] = 0, cost[id] = -d;
}
int que[200010], dep[200010], hd, tl;
int dist[100010];
inline bool BFS() {
  memset(dist, 63, 4 * (T + 1));
  hd = tl = 100010;
  que[tl++] = S;
  dist[S] = 0;
  while (hd ^ tl) {
    int x = que[hd++];
    for (int i = fir[x]; i; i = nxt[i])
      if (w[i] && dist[dis[i]] > dist[x] + cost[i]) {
        dist[dis[i]] = dist[x] + cost[i];
        dep[dis[i]] = dep[x] + 1;
        if (cost[i])
          que[tl++] = dis[i];
        else
          que[--hd] = dis[i];
      }
  }
  return dist[T] < 1e8;
}
int COST;
inline int Dinic(int x, int maxflow) {
  if (x == T) return maxflow;
  int ret = 0;
  for (int& i = head[x]; i; i = nxt[i])
    if (w[i] && dist[dis[i]] == dist[x] + cost[i] &&
        dep[dis[i]] == dep[x] + 1) {
      int d = Dinic(dis[i], std::min(w[i], maxflow - ret));
      w[i] -= d, w[i ^ 1] += d, ret += d, COST += 1ll * d * cost[i];
      if (maxflow == ret) break;
    }
  return ret;
}
inline int Mincost() {
  COST = 0;
  while (BFS()) memcpy(head, fir, (T + 1) * 4), Dinic(S, 1e9);
  return COST;
}
}  // namespace flow
int main() {
  int n = gi(), m = gi(), a, b;
  for (int i = 1; i <= m; ++i) a = gi(), b = gi(), link(a, b), link(b, a);
  if (m == n - 1) {
    dfs(1);
    for (int i = 1; i <= n; ++i) ans += abs(f[i]);
    if (f[1]) ans = -1;
    printf("%d\n", ans);
  } else {
    pre_dfs(1);
    for (int i = 1; i <= p; ++i) cir[i + p] = cir[i];
    cir[0] = cir[p];
    for (int i = 1; i <= p; ++i) dfs(cir[i], cir[i - 1], cir[i + 1]);
    for (int i = 1; i <= n; ++i) ans += abs(f[i]);
    for (int i = 1; i <= p; ++i) ans -= abs(f[cir[i]]);
    if (p % 2 == 0) {
      flow::S = 0, flow::T = p + 1;
      for (int i = 1; i <= p; ++i)
        flow::link(i, i % p + 1, 1e9, 1), flow::link(i % p + 1, i, 1e9, 1);
      int A = 0, B = 0;
      for (int i = 1; i <= p; ++i) {
        if (f[cir[i]] > 0) {
          if (i & 1)
            A += f[cir[i]], flow::link(flow::S, i, f[cir[i]], 0);
          else
            B += f[cir[i]], flow::link(i, flow::T, f[cir[i]], 0);
        } else if (f[cir[i]] < 0) {
          if (i & 1)
            B -= f[cir[i]], flow::link(i, flow::T, -f[cir[i]], 0);
          else
            A -= f[cir[i]], flow::link(flow::S, i, -f[cir[i]], 0);
        }
      }
      if (A != B) {
        puts("-1");
        return 0;
      }
      ans += flow::Mincost();
    } else {
      for (int i = 1, t = -1; i < p; ++i, t = -t) f[cir[p]] += t * f[cir[i]];
      if (f[cir[p]] % 2) return puts("-1"), 0;
      f[cir[p]] /= 2;
      for (int i = p - 1; i; --i) f[cir[i]] -= f[cir[i + 1]];
      for (int i = 1; i <= p; ++i) ans += abs(f[cir[i]]);
    }
    printf("%d\n", ans);
  }
  return 0;
}
