#include <bits/stdc++.h>
using namespace std;
inline void read(int& x) {
  char c11 = getchar();
  x = 0;
  while (!isdigit(c11)) c11 = getchar();
  while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
}
const int N = 101000;
struct Edge {
  int v, nxt;
} a[N << 1];
int head[N];
int n, m, _;
long long ans;
inline void add(int u, int v) {
  a[++_].v = v, a[_].nxt = head[u], head[u] = _;
  a[++_].v = u, a[_].nxt = head[v], head[v] = _;
}
int dfs(int x, int las, int sgn) {
  int t, sz = sgn;
  for (int i = head[x]; i; i = a[i].nxt)
    if (a[i].v != las) {
      t = dfs(a[i].v, x, -sgn);
      sz += t, ans += abs(t);
    }
  return sz;
}
void init();
int main() {
  init();
  if (dfs(1, 0, 1))
    puts("-1");
  else
    printf("%lld\n", ans);
  return 0;
}
void init() {
  read(n), read(m);
  int u, v;
  while (m--) {
    read(u), read(v);
    add(u, v);
  }
}
