#include <bits/stdc++.h>
using namespace std;
int N, M;
int mvs[100005], col[100005];
vector<int> edg[100005];
int f[100005];
void DFS(int nod, int fth) {
  if (f[nod]) return;
  f[nod] = 1;
  for (auto nxt : edg[nod]) {
    if (nxt == fth) continue;
    DFS(nxt, nod);
    mvs[nod] += mvs[nxt];
    if (col[nxt] == 0) {
      mvs[nod]++;
      col[nod] ^= 1;
    }
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    edg[x].push_back(y);
    edg[y].push_back(x);
  }
  DFS(1, 0);
  printf("%d\n", col[1] == 0 ? -1 : mvs[1]);
  return 0;
}
