#include <bits/stdc++.h>
using namespace std;
vector<int> w[120001];
int n, m, s, d[120001], f[120001], cnt[120001], need[120001];
void dfs(int u, int p, int dep) {
  if (dep & 1)
    s++, cnt[u]++;
  else
    need[u]++;
  d[u] = dep;
  f[u] = p;
  for (int v : w[u])
    if (v != p) dfs(v, u, dep + 1), cnt[u] += cnt[v], need[u] += need[v];
}
inline void add(int u, int k) {
  while (u) cnt[u] += k, u = f[u];
}
int p[120001], b, e;
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
inline int eval(int k) {
  if (k) add(b, k), add(e, -k);
  int ans = 0;
  for (int i = 2; i <= n; i++) ans += abs(need[i] - cnt[i]);
  if (k) add(b, -k), add(e, k);
  return ans;
}
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int x = find(u), y = find(v);
    if (x == y)
      b = u, e = v;
    else
      w[u].push_back(v), w[v].push_back(u), p[x] = y;
  }
  dfs(1, 0, 0);
  if (m == n - 1)
    printf("%d\n", s * 2 != n ? -1 : eval(0));
  else if ((d[b] - d[e]) & 1) {
    int l = -n, r = n, ans = 1 << 30;
    while (l + 5 <= r) {
      int l3 = (l + l + r) / 3, r3 = (l + r + r) / 3, vl = eval(l3) + abs(l3),
          vr = eval(r3) + abs(r3);
      if (vl < vr)
        r = r3;
      else
        l = l3;
    }
    for (int i = l; i <= r; i++) ans = min(ans, eval(i) + abs(i));
    printf("%d\n", ans);
  } else {
    if ((n - s - s) % 2) {
      puts("-1");
      return 0;
    }
    int k = (n - s - s) / 2;
    add(b, k);
    add(e, k);
    printf("%d\n", abs(k) + eval(0));
  }
  return 0;
}
