#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct edge {
  int k, next;
} e[100005 << 1];
int home[100005], cnt = -1, n, m, fa[100005], sx, sy;
long long f[100005], w[100005];
int find(int k) {
  if (fa[k] != k) fa[k] = find(fa[k]);
  return fa[k];
}
void add(int x, int y) {
  cnt++;
  e[cnt].k = y;
  e[cnt].next = home[x];
  home[x] = cnt;
}
long long Abs(long long a) { return a < 0 ? -a : a; }
void dfs(int k, int F, int dep) {
  if (dep & 1)
    w[k]++;
  else
    w[k]--;
  for (int i = home[k]; ~i; i = e[i].next) {
    if (e[i].k != F) {
      dfs(e[i].k, k, dep + 1);
    }
  }
}
int main() {
  memset(home, -1, sizeof(home));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (find(x) != find(y)) {
      add(x, y);
      add(y, x);
      fa[find(x)] = find(y);
    } else {
      sx = x;
      sy = y;
    }
  }
  dfs(1, 0, 1);
  if (w[1] != 0)
    return puts("-1");
  else
    printf("%lld", f[1]);
  return 0;
}
