#include <bits/stdc++.h>
using namespace std;
const int inf = 1.01e9;
const double eps = 1e-9;
const int N = 1e5 + 10;
int mark[N];
vector<int> v[N];
int d[N][2];
long long res = 0;
void dfs(int x) {
  mark[x] = 1;
  d[x][0] = 1;
  d[x][1] = 0;
  for (int y : v[x]) {
    if (mark[y] == 1) continue;
    dfs(y);
    d[x][0] += d[y][1];
    d[x][1] += d[y][0];
  }
  res += abs(d[x][0] - d[x][1]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == m) return 0;
  for (int i = 0; (i) < (n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0);
  if (d[0][0] != d[0][1]) res = -1;
  printf("%lld\n", res);
  return 0;
}
