#include <bits/stdc++.h>
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
int n, m, cnt, tmp, head[100010], sum[100010];
long long ans = 0;
struct edge {
  int to, nxt;
} e[100010 << 1];
void adde(int x, int y) {
  e[++cnt].to = y;
  e[cnt].nxt = head[x];
  head[x] = cnt;
}
void ins(int x, int y) {
  adde(x, y);
  adde(y, x);
}
void dfs(int u, int fa, int d) {
  sum[u] = 0;
  for (int i = head[u], v; i; i = e[i].nxt)
    if ((v = e[i].to) != fa) {
      dfs(v, u, -d);
      sum[u] += sum[v];
    }
  sum[u] += d;
  tmp += d;
  ans += abs(sum[u]);
}
int main() {
  n = read();
  m = read();
  for (int i = (1); i <= (m); i++) {
    int x = read(), y = read();
    ins(x, y);
  }
  ans = 0;
  dfs(1, 0, 1);
  if (tmp)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
