#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x, y, next;
} a[200010 * 2];
int n, m, l, p[200010], x, y, def[200010], sum[200010];
long long f_tree[200010];
inline void add(int x, int y) {
  a[++l].x = x;
  a[l].y = y;
  a[l].next = p[x];
  p[x] = l;
}
inline void dp_tree(int x, int fa) {
  for (int i = p[x]; i; i = a[i].next)
    if (fa != a[i].y) {
      def[a[i].y] = def[x] + 1;
      dp_tree(a[i].y, x);
    }
  sum[x] = f_tree[x] = 0;
  int s1 = 0, s2 = 0;
  for (int i = p[x]; i; i = a[i].next)
    if (fa != a[i].y) {
      f_tree[x] += f_tree[a[i].y];
      if (sum[a[i].y] <= 0)
        s2 += -sum[a[i].y];
      else
        s1 += sum[a[i].y];
    }
  f_tree[x] += 2 * min(s1, s2) + max(s1 - s2, s2 - s1);
  sum[x] = s1 - s2;
  if (def[x] & 1)
    sum[x]++;
  else
    sum[x]--;
}
int main() {
  scanf("%d%d", &n, &m);
  l = 0;
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  if (m == n - 1) {
    def[1] = 1;
    dp_tree(1, 0);
    if (sum[1])
      printf("-1");
    else
      printf("%lld", f_tree[1]);
    return 0;
  }
  if (m == n) {
  }
  return 0;
}
