#include <bits/stdc++.h>
using namespace std;
struct edges {
  int to, next;
} edge[202020];
int first[101010], now;
void adde(int x, int y) {
  now++;
  edge[now].to = y;
  edge[now].next = first[x];
  first[x] = now;
}
long long cnt1[101010], cnt2[101010];
long long ans = 0;
void work(int p, int fa) {
  for (int e = first[p]; e; e = edge[e].next)
    if (edge[e].to != fa) {
      work(edge[e].to, p);
      cnt1[p] += cnt1[edge[e].to];
      cnt2[p] += cnt2[edge[e].to];
    }
  if (cnt1[p] > cnt2[p]) {
    cnt2[p] = cnt1[p] - 1 - cnt2[p];
    cnt1[p] = 0;
  } else {
    cnt1[p] = cnt2[p] + 1 - cnt1[p];
    cnt2[p] = 0;
  }
  ans += cnt1[p] + cnt2[p];
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  memset(cnt1, 0, sizeof(cnt1));
  memset(cnt2, 0, sizeof(cnt2));
  memset(first, 0, sizeof(first));
  now = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    adde(x, y);
    adde(y, x);
  }
  work(1, 0);
  if (cnt1[1] == 0 && cnt2[1] == 0)
    printf("%lld\n", ans);
  else
    printf("-1\n");
  return 0;
}
