#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 100;
vector<int> g[N];
int eA, eB;
int ans;
int color[N];
int val[N];
void dfsColor(int v, int par, int c) {
  color[v] = c;
  for (int to : g[v]) {
    if (to == par) continue;
    if (color[to] != 0) {
      eA = min(v, to);
      eB = max(v, to);
      continue;
    }
    dfsColor(to, v, c ^ 3);
  }
}
int solve(int v, int par) {
  int x = val[v];
  for (int to : g[v]) {
    if (to == par) continue;
    if (min(v, to) == eA && max(v, to) == eB) continue;
    x += solve(to, v);
  }
  ans += abs(x);
  return -x;
}
int main(int, char **) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  memset(val, -1, sizeof val);
  if (m == n) {
    dfsColor(0, 0, 1);
    if (color[eA] == color[eB]) {
      int cnt[3] = {0, 0, 0};
      for (int i = 0; i < n; i++) {
        cnt[color[i]]++;
      }
      int x = (cnt[color[eA]] - cnt[color[eA] ^ 3]) / 2;
      val[eA] += x;
      val[eB] += x;
      ans += x;
    } else
      throw;
  }
  if (solve(0, 0) != 0) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", ans);
  return 0;
}
