#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n, m, head[100000 + 5], cnt = 0, flag = 1, ans = 0, f[100000 + 5];
struct edge {
  int to, next;
} e[100000 * 2 + 5];
inline void ins(int f, int t) {
  e[++cnt] = (edge){t, head[f]};
  head[f] = cnt;
  e[++cnt] = (edge){f, head[t]};
  head[t] = cnt;
}
void dfs(int x, int fa = 0) {
  int num1 = 0, num2 = 0;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa) {
      dfs(e[i].to, x);
      if (f[e[i].to] == 1) ++num1;
      if (f[e[i].to] == -1) ++num2;
    }
  if (num1 < num2 || num1 > num2 + 2) flag = 0;
  if (num1 == num2)
    f[x] = 1;
  else if (num1 == num2 + 1)
    f[x] = 0;
  else if (num1 == num2 + 2)
    f[x] = -1;
  if (f[x] != 0) ++ans;
}
int main() {
  n = read();
  m = read();
  if (m < n) {
    for (int i = 1; i < n; ++i) ins(read(), read());
    dfs(1);
    if (f[1] != 0) flag = 0;
    printf("%d\n", flag ? ans : -1);
  } else {
  }
  return 0;
}
