#include <bits/stdc++.h>
int read() {
  static int x;
  scanf("%d", &x);
  return x;
}
const int MAXN = 1e5 + 1;
struct Edge {
  int to;
  Edge *next;
  Edge() {}
  Edge(int v, Edge *e) : to(v), next(e) {}
  void *operator new(size_t);
} Edata[MAXN * 2], *head[MAXN];
void *Edge::operator new(size_t) {
  static Edge *P = Edata;
  return P++;
}
void addEdge(int a, int b) {
  head[a] = new Edge(b, head[a]);
  head[b] = new Edge(a, head[b]);
}
int cnt[MAXN], fa[MAXN];
int Q[MAXN], qL, qR;
int bfs(int p) {
  int sum = 0;
  cnt[p] = 1;
  Q[qR++] = p;
  while (qL < qR) {
    p = Q[qL++];
    sum += cnt[p];
    for (Edge *e = head[p]; e; e = e->next)
      if (e->to != fa[p]) cnt[e->to] = -cnt[p], fa[e->to] = p, Q[qR++] = e->to;
  }
  return sum;
}
int main() {
  int N, i, p;
  N = read();
  read();
  for (i = 1; i < N; ++i) addEdge(read(), read());
  if (bfs(1)) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (i = qR - 1; i > 0; --i) {
    p = Q[i];
    ans += ((cnt[p]) < 0 ? (-(cnt[p])) : (cnt[p]));
    cnt[fa[p]] += cnt[p];
  }
  printf("%d\n", ans);
}
