#include <bits/stdc++.h>
using namespace std;
int n, m;
int head[100005], cnt;
int f[100005][2];
struct data {
  int next, to;
  data(int next = 0, int to = 0) : next(next), to(to) {}
} edge[100005 << 1];
void connect(int u, int v) {
  edge[++cnt] = data(head[u], v);
  head[u] = cnt;
}
int read() {
  char c = getchar();
  int x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
void DFS(int u, int pre) {
  f[u][1] = 0x3f3f3f3f;
  for (int i = head[u]; i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == pre) continue;
    DFS(v, u);
    int f0 = f[u][0], f1 = f[u][1];
    f[u][0] = min(f0 + f[v][1], f1 + f[v][0] + 1);
    f[u][1] = min(f0 + f[v][0] + 1, f1 + f[v][1]);
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    connect(u, v);
    connect(v, u);
  }
  DFS(1, 0);
  printf("%d\n", f[1][1] >= 0x3f3f3f3f ? -1 : f[1][1]);
}
