#include <bits/stdc++.h>
using namespace std;
struct E {
  int to, nxt;
} ed[100005 << 1];
int n, m, i, j, k, top;
int head[100005], a[100005], b[100005], jo[100005], num[100005];
long long ans;
void read(int &p) {
  p = 0;
  char x = getchar();
  while (x < '0' || x > '9') x = getchar();
  while (x >= '0' && x <= '9') {
    p = p * 10 + x - '0';
    x = getchar();
  }
}
void add(int u, int v) {
  top++;
  ed[top] = (E){v, head[u]};
  head[u] = top;
}
void solve(int x, int fa) {
  int i, g0 = 1, g1 = 0, v;
  for (i = head[x]; i; i = ed[i].nxt)
    if ((v = ed[i].to) != fa) {
      solve(v, x);
      if (jo[v])
        g0 += num[v];
      else
        g1 += num[v];
    }
  if (g0 && g1) {
    if (g0 >= g1) {
      jo[x] = 0;
      num[x] = g0 - g1;
      ans += (g1 << 1) - 2;
    } else {
      jo[x] = 1;
      num[x] = g1 - g0;
      ans += (g0 << 1) - 2;
    }
    ans += (num[x] << 1);
  } else {
    jo[x] = 0;
    num[x] = g0;
    ans += (g0 << 1) - 2;
    ans += ((num[x] - 1) << 1);
  }
}
int main() {
  read(n);
  read(m);
  for (i = 1; i <= m; ++i) {
    read(a[i]);
    read(b[i]);
    add(a[i], b[i]);
    add(b[i], a[i]);
  }
  ans = n;
  solve(1, 0);
  if (num[1])
    puts("-1");
  else
    printf("%lld\n", ans >> 1);
  return 0;
}
