#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> cycle;
int tmp[114514];
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, int d) {
  if (sumi[v]) {
    if (cycle.size() > 0) return;
    int t = 0;
    while (tmp[t] != v && t < d) t++;
    for (int i = t; i < d; i++) cycle.push_back(tmp[i]);
    return;
  }
  tmp[d] = 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, d + 1);
  }
}
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;
  }
  return 0;
}
