#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e5 + 5;
long long n, m, ans, U;
bool type[MAX_N];
long long val[MAX_N];
bool mark[MAX_N];
bool cycle[MAX_N];
vector<long long> G[MAX_N];
vector<long long> vec, Cy;
void dfsTree(long long v = 0, long long p = 0) {
  long long tmp[] = {0, 0};
  for (long long u : G[v])
    if (u != p && !cycle[u]) {
      dfsTree(u, v);
      tmp[type[u]] += val[u];
    }
  val[v] = min(tmp[0], tmp[1]);
  tmp[0] -= val[v], tmp[1] -= val[v];
  if (!tmp[0] && !tmp[1]) {
    type[v] = 0;
    val[v] = 1;
    ans++;
    return;
  }
  if (tmp[0]) {
    type[v] = 1;
    val[v] = tmp[0] - 1;
    ans += val[v];
  } else {
    type[v] = 0;
    val[v] = 1 + tmp[1];
    ans += val[v];
  }
}
bool dfs(long long v = 0, long long p = 0) {
  mark[v] = true;
  vec.push_back(v);
  for (int u : G[v])
    if (u != p) {
      if (mark[u]) {
        U = u;
        return true;
      }
      if (dfs(u, v)) return true;
    }
  vec.pop_back();
  return false;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long v, u;
    cin >> v >> u;
    v--, u--;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  if (n & 1) {
    cout << "-1\n";
    return 0;
  }
  if (n - 1 == m) {
    dfsTree();
    if (val[0])
      cout << "-1\n";
    else {
      cout << ans << "\n";
    }
    return 0;
  }
  dfs();
  int ind = 0;
  for (int i = 0; i < vec.size(); i++)
    if (vec[i] == U) {
      ind = i;
      break;
    }
  for (int i = ind; i < vec.size(); i++) {
    cycle[vec[i]] = true;
    Cy.push_back(vec[i]);
  }
  long long sum = 0;
  for (int v : Cy) dfsTree(v, v);
  for (int i = 0; i < Cy.size(); i++) {
    int v = Cy[i];
    int u = Cy[(i + 1) % Cy.size()];
    if (type[v] != type[u]) continue;
    long long tmp = min(val[v], val[u]);
    val[v] -= tmp;
    val[u] -= tmp;
  }
  for (int v : Cy)
    if (val[v] && type[v] == 0) {
      cout << "-1\n";
      return 0;
    }
  assert(false);
  return 0;
}
