#include <bits/stdc++.h>
inline int Get() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int Num = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9')
    Num = (Num << 3) + (Num << 1) + ch - '0';
  return Num;
}
const int N = 1e5 + 5;
int n, m, que[N], qn, fa[N], g[N];
int tot, first[N], next[N << 1], end[N << 1];
inline void AddEdge(int x, int y) {
  next[++tot] = first[x], first[x] = tot, end[tot] = y;
  next[++tot] = first[y], first[y] = tot, end[tot] = x;
}
int calc(int x) {
  que[qn = 1] = x, fa[x] = 0;
  for (int ql = 1, u; u = que[ql], ql <= qn; ++ql)
    for (int k = first[u], v; v = end[k], k; k = next[k])
      if (v != fa[u]) fa[v] = u, que[++qn] = v;
  int res = 0;
  for (int qr = qn, u; u = que[qr], qr; --qr)
    for (int k = first[u], v; v = end[k], k; k = next[k])
      if (v != fa[u]) {
        int delta = 1 - g[v];
        res += delta > 0 ? delta : -delta;
        g[u] += delta, g[v] += delta;
      }
  return g[x] == 1 ? res : -1;
}
int main() {
  n = Get(), m = Get();
  for (int i = 1; i < n; ++i) AddEdge(Get(), Get());
  if (n == m) {
    puts("-1");
    return 0;
  }
  printf("%d\n", calc(1));
}
