#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long n, m, ans;
vector<int> g[MAXN];
bool isc[MAXN];
int deg[MAXN];
int p[MAXN];
vector<int> gg[MAXN];
vector<int> c, d;
pair<long long, long long> dfs(int v, int f = -1) {
  pair<long long, long long> tot = pair<long long, long long>(0, 0);
  for (int u : g[v]) {
    if (isc[u] || u == f) continue;
    pair<long long, long long> t = dfs(u, v);
    tot.first += t.first;
    tot.second += t.second;
  }
  if (tot.first >= tot.second)
    tot.first -= tot.second, tot.second = 0;
  else
    tot.second -= tot.first, tot.first = 0;
  if (tot.second >= 1)
    tot.second--;
  else
    tot.first++;
  if (!isc[v]) ans += (tot.first + tot.second);
  swap(tot.first, tot.second);
  return tot;
}
void findc() {
  set<pair<long long, long long> > s;
  for (int i = 0; i < n; ++i) {
    deg[i] = g[i].size();
    s.insert(pair<long long, long long>(deg[i], i));
  }
  while (!s.empty()) {
    pair<long long, long long> t = (*s.begin());
    if (t.first == 2) break;
    s.erase(t);
    for (int u : g[t.second]) {
      s.erase(pair<long long, long long>(deg[u], u));
      deg[u]--;
      s.insert(pair<long long, long long>(deg[u], u));
    }
  }
  for (pair<long long, long long> t : s) isc[t.second] = 1;
}
void dfsc(int v, int f = -1) {
  d.push_back(v);
  if (gg[v][0] != f && gg[v][0] != d[0]) {
    dfsc(gg[v][0], v);
  } else if (gg[v][1] != f && gg[v][1] != d[0]) {
    dfsc(gg[v][1], v);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (m == n - 1) {
    g[0].push_back(g[0][0]);
    g[g[0][0]].push_back(0);
  }
  if (n % 2 == 1) {
    cout << "-1\n";
    return 0;
  }
  findc();
  for (int i = 0; i < n; ++i)
    if (isc[i]) {
      c.push_back(i);
      pair<long long, long long> t = dfs(i, -1);
      p[i] = t.first - t.second;
    }
  for (int i : c)
    for (int j : g[i])
      if (isc[j]) gg[i].push_back(j);
  dfsc(c[0]);
  c = d;
  if (c.size() % 2 == 1) {
    long long x = 0;
    for (int i : c) x = -x + p[i];
    x /= 2;
    ans += abs(x);
    for (int i = 0; i < c.size() - 1; ++i) {
      x = -x + p[c[i]];
      ans += abs(x);
    }
    cout << ans << endl;
  } else {
    long long s1 = 0, s2 = 0;
    for (int i = 0; i < c.size(); i += 2) s1 += p[c[i]], s2 += p[c[i + 1]];
    if (s1 != s2) {
      cout << "-1\n";
      return 0;
    }
    vector<int> b;
    b.push_back(0);
    long long x = 0;
    for (int i = 0; i < c.size() - 1; ++i) {
      x = -x + p[c[i]];
      if (i % 2 == 0)
        b.push_back(-x);
      else
        b.push_back(x);
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < c.size() / 2; ++i) ans += b[i + c.size() / 2] - b[i];
    cout << ans << endl;
  }
}
