#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, tot, head[300000], f[300000], g[300000], fa[300000];
struct edge {
  long long v, nxt;
} e[300000];
void add(long long x, long long y) {
  e[++tot].v = y;
  e[tot].nxt = head[x];
  head[x] = tot;
}
void dfs(long long u, long long o) {
  f[u] = 0;
  g[u] = o;
  for (long long i = head[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa[u]) {
      fa[v] = u;
      dfs(v, -o);
      f[u] += f[v] + abs(g[v]);
      g[u] += g[v];
    }
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; ++i) {
    scanf("%lld%lld", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 1);
  printf("%lld\n", g[1] ? -1 : f[1]);
  return 0;
}
