#include <bits/stdc++.h>
using namespace std;
vector<int> gr[114514];
int pat[114514];
long long st[114514], go[114514], inp[114514];
bool sumi[114514];
int num[3];
int out = 0, ng1 = -1, ng2 = -1;
vector<int> tmp, cycle;
void dfs(int v, int p) {
  if (pat[v] >= 0) return;
  pat[v] = p;
  num[pat[v]]++;
  for (int i = 0; i < gr[v].size(); i++) {
    int w = gr[v][i];
    if (v == ng1 && w == ng2) continue;
    if (v == ng2 && w == ng1) continue;
    dfs(w, 1 - p);
  }
}
void dfs2(int v, int u) {
  for (int i = 0; i < gr[v].size(); i++) {
    int w = gr[v][i];
    if (w == u) continue;
    if (v == ng1 && w == ng2) continue;
    if (v == ng2 && w == ng1) continue;
    dfs2(w, v);
    out += abs(st[w] - go[w]);
    st[v] += st[w];
    go[v] += go[w];
  }
  if (pat[v] == 1)
    st[v]++;
  else
    go[v]++;
}
long long cal(long long mi) {
  memset(st, 0, sizeof(st));
  memset(go, 0, sizeof(go));
  st[ng1] = mi;
  go[ng2] = mi;
  out = 0;
  dfs2(0, -1);
  return abs(mi) + out;
}
void dfscycle(int v, int u) {
  if (sumi[v]) {
    int t = 0;
    while (tmp[t] != v) t++;
    for (int i = t; i < tmp.size(); i++) cycle.push_back(tmp[i]);
    return;
  }
  tmp.push_back(v);
  sumi[v] = true;
  for (int i = 0; i < gr[v].size(); i++) {
    int w = gr[v][i];
    if (w == u) continue;
    dfscycle(w, v);
  }
  tmp.pop_back();
}
int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  if (n % 2 > 0) {
    cout << -1 << endl;
    return 0;
  }
  memset(num, 0, sizeof(num));
  memset(pat, -1, sizeof(pat));
  memset(st, 0, sizeof(st));
  memset(go, 0, sizeof(go));
  if (m == n - 1) {
    dfs(0, 0);
    if (num[0] != num[1]) {
      cout << -1 << endl;
      return 0;
    }
    dfs2(0, -1);
    cout << out << endl;
    return 0;
  }
  dfscycle(0, -1);
  ng1 = cycle[0];
  ng2 = cycle[1];
  return 0;
  if (cycle.size() % 2 == 0) {
    dfs(0, 0);
    if (num[0] != num[1]) {
      cout << -1 << endl;
      return 0;
    }
    int lo = -114514, hi = 114514;
    long long out = 1145141919810364364LL;
    while (hi > lo + 5) {
      long long m1 = (lo + hi) / 2, m2 = m1 + 1, x1 = cal(m1), x2 = cal(m2);
      if (x1 > x2)
        lo = m1;
      else
        hi = m2;
    }
    for (int i = lo; i < hi + 1; i++) out = min(out, cal(i));
    cout << out << endl;
    return 0;
  }
  dfs(ng1, 0);
  pat[ng2] = 0;
  if (num[0] > num[1])
    st[ng1] = st[ng2] = (num[0] - num[1]) / 2;
  else
    go[ng1] = go[ng2] = (num[1] - num[0]) / 2;
  dfs2(0, -1);
  cout << out + abs((num[0] - num[1]) / 2) << endl;
}
