#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> adj[100010], tree[100010];
int tin[100010], tout[100010], capa[100010], sz0[100010], sz1[100010],
    timer = 0, ans = 0, A, B, X;
int f(int u) { return abs(sz0[u] - sz1[u]); }
void dfs0(int u, int p, int d) {
  tin[u] = timer++;
  capa[u] = d;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    if (tin[v] != -1) {
      if (tin[v] < tin[u]) A = u, B = v;
      continue;
    }
    dfs0(v, u, d ^ 1);
    tree[u].push_back(v);
  }
  tout[u] = timer;
}
void dfs2(int u) {
  sz0[u] = capa[u] ^ 1;
  sz1[u] = capa[u];
  for (int i = 0; i < tree[u].size(); i++) {
    int v = tree[u][i];
    dfs2(v);
    sz0[u] += sz0[v];
    sz1[u] += sz1[v];
  }
}
vector<int> val;
void dfs1(int u) {
  for (int i = 0; i < tree[u].size(); i++) {
    int v = tree[u][i];
    dfs1(v);
  }
  if (u) {
    if (tin[u] <= tin[A] && tin[A] < tout[u] &&
        !(tin[u] <= tin[B] && tin[B] < tout[u])) {
      if (sz1[u] >= sz0[u])
        val.push_back(f(u));
      else
        val.push_back(-f(u));
    } else if (!(tin[u] <= tin[A] && tin[A] < tout[u]) && tin[u] <= tin[B] &&
               tin[B] < tout[u]) {
      if (sz1[u] >= sz0[u])
        val.push_back(-f(u));
      else
        val.push_back(f(u));
    } else {
      ans += f(u);
    }
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(tin, -1, sizeof(tin));
  dfs0(0, -1, 0);
  dfs2(0);
  if (M == N - 1) {
    if (sz1[0] * 2 != N) {
      printf("-1");
      return 0;
    }
    for (int i = 1; i < N; i++) ans += f(i);
    printf("%d", ans);
    return 0;
  }
  if (capa[A] == capa[B]) {
    if (N % 2) {
      printf("-1");
      return 0;
    }
    if (N < 2 * sz1[0]) {
      for (int i = 0; i < N; i++) tree[i].clear();
      memset(tin, -1, sizeof(tin));
      timer = 0;
      dfs0(0, -1, 1);
      dfs2(0);
    }
    capa[A] += (N - 2 * sz1[0]) / 2;
    capa[B] += (N - 2 * sz1[0]) / 2;
    ans += abs((N - 2 * sz1[0]) / 2);
    dfs2(0);
    for (int i = 1; i < N; i++) ans += f(i);
    printf("%d", ans);
    return 0;
  }
  if (sz1[0] * 2 != N) {
    printf("-1");
    return 0;
  }
  dfs1(0);
  val.push_back(0);
  sort(val.begin(), val.end());
  int mid = val[val.size() / 2];
  for (int i = 0; i < val.size(); i++) {
    ans += abs(val[i] - mid);
  }
  printf("%d", ans);
}
