#include <bits/stdc++.h>
using namespace std;
struct edge {
  int t, next;
} e[100005 * 2];
int ecnt, head[100005];
void addedge(int f, int t) {
  e[++ecnt] = (edge){t, head[f]};
  head[f] = ecnt;
  e[++ecnt] = (edge){f, head[t]};
  head[t] = ecnt;
}
long long ans;
int ini[100005], ax[100005], delta[100005], del;
void DFS(int u, int fr) {
  delta[u] = ini[u];
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].t != fr && i != del && i != (del ^ 1)) {
      DFS(e[i].t, u);
      delta[u] -= delta[e[i].t];
      ax[u] -= ax[e[i].t];
    }
  }
  ax[u] == 0 ? ans += abs(delta[u]) : 0;
}
int vis[100005], num[2], A, B, type[100005];
void DFS2(int u, int fr, int side) {
  num[side]++;
  vis[u] = 1;
  type[u] = side;
  for (int i = head[u]; i; i = e[i].next) {
    if (vis[e[i].t] == 0) {
      DFS2(e[i].t, u, side ^ 1);
    } else {
      A = u;
      B = e[i].t;
      del = i;
    }
  }
}
int n, m;
void solve1() {
  del = 0;
  DFS(1, 0);
  if (delta[1] != 0) puts("-1"), exit(0);
}
void solve2() {
  DFS2(1, 0, 0);
  if (type[A] == type[B]) {
    int t = (num[type[A] ^ 1] - num[type[A]]) / 2;
    ini[A] += t;
    ini[B] += t;
    DFS(A, 0);
    ans += abs(t);
  } else {
    if (num[0] != num[1]) puts("-1"), exit(0);
    ax[B] = -1;
    DFS(A, 0);
    vector<int> v;
    for (int i = 1; i <= n; i++) v.push_back(-ax[i] * delta[i]);
    sort(v.begin(), v.end());
    for (int i = 0, mid = v[v.size() / 2]; i < v.size(); i++)
      ans += abs(mid - v[i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  ecnt = 1;
  if (n % 2 != 0) return puts("-1"), 0;
  for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), addedge(u, v);
  for (int i = 1; i <= n; i++) ini[i] += 1;
  if (m == n - 1)
    solve1();
  else
    solve2();
  cout << ans << endl;
  return 0;
}
