#include <bits/stdc++.h>
using namespace std;
const int Size = 1 << 16;
char buffer[Size], *head, *tail;
inline char Getchar() {
  if (head == tail) {
    int l = fread(buffer, 1, Size, stdin);
    tail = (head = buffer) + l;
  }
  if (head == tail) return -1;
  return *head++;
}
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int maxn = 100010;
const int inf = 1e9;
int n, m, first[maxn], nxt[maxn << 1], to[maxn << 1], e;
void AddEdge(int u, int v) {
  to[++e] = v;
  nxt[e] = first[u];
  first[u] = e;
  to[++e] = u;
  nxt[e] = first[v];
  first[v] = e;
}
long long ans;
int dfs(int x, int fa, int dep) {
  int cur = (dep & 1) ? 1 : -1;
  for (int i = first[x]; i; i = nxt[i])
    if (to[i] != fa) cur += dfs(to[i], x, dep + 1);
  ans += abs(cur);
  return cur;
}
int main() {
  n = read();
  m = read();
  for (int i = (1), i_end_ = (m); i <= i_end_; i++) AddEdge(read(), read());
  if (dfs(1, 0, 1))
    puts("-1");
  else
    printf("%lld\n", ans);
  return 0;
}
