#include <bits/stdc++.h>
int N, M, head[100001], next[200001], to[200001], E, q[100001], fa[100001],
    dep[100001], fe[100001], v[100001], size[100001][2];
inline void add(int u, int v) {
  next[++E] = head[u], to[E] = v, head[u] = E;
  next[++E] = head[v], to[E] = u, head[v] = E;
}
void Tree() {
  for (int i = 1, u, v; i < N; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
  }
  int H = 0, T = 1, u;
  q[1] = 1;
  while (H < T)
    for (int e = head[u = q[++H]]; e; e = next[e])
      if (to[e] != fa[u]) {
        fa[q[++T] = to[e]] = u;
        dep[to[e]] = dep[u] + 1;
      }
  for (int i = N; i; i--) {
    int u = q[i];
    size[u][dep[u] & 1] = 1;
    for (int e = head[u]; e; e = next[e])
      if (to[e] != fa[u]) {
        size[u][0] += size[to[e]][0];
        size[u][1] += size[to[e]][1];
      }
  }
  if (size[1][0] != size[1][1])
    puts("-1");
  else {
    long long O = 0;
    for (int i = 2; i <= N; i++)
      O += std::max(size[i][0] - size[i][1], size[i][1] - size[i][0]);
    printf("%lld\n", O);
  }
}
void Circle() {}
int main() {
  scanf("%d%d", &N, &M);
  if (N & 1) {
    puts("-1");
    return 0;
  }
  if (M == N - 1)
    Tree();
  else
    Circle();
  return 0;
}
