#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct edge {
  int to, nxt;
} e[N << 1];
int head[N], tot = 1;
void adde(int x, int y) {
  e[tot] = (edge){y, head[x]};
  head[x] = tot++;
}
int sum[N], dep[N];
long long ans = 0;
void dfs(int u, int f) {
  sum[u] = ((dep[u] & 1) ? 1 : -1);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == f) continue;
    dep[v] = dep[u] + 1, dfs(v, u);
    sum[u] += sum[v];
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y), adde(x, y), adde(y, x);
  }
  if (1) {
    if (n & 1) {
      printf("-1\n");
      return 0;
    }
    dfs(1, 1);
    if (sum[1]) {
      printf("-1\n");
      return 0;
    }
    for (int i = 2; i <= n; i++) ans += abs(sum[i]);
    printf("%lld\n", ans);
  }
}
