#include <bits/stdc++.h>
using namespace std;
int x, y, n, m, s[100005], dep[100005];
long long ans, sum;
vector<int> e[100005];
void dfs1(int x, int fa) {
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) dep[e[x][i]] = dep[x] + 1, dfs1(e[x][i], x);
}
int dfs2(int x, int fa) {
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa) s[x] += dfs2(e[x][i], x);
  return s[x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++)
    scanf("%d%d", &x, &y), e[x].push_back(y), e[y].push_back(x);
  if (m == n) {
    puts("-1");
    return 0;
  }
  dep[1] = 1;
  dfs1(1, 0);
  for (int i = 1; i <= n; i++) s[i] = (dep[i] & 1) ? 1 : -1, sum += s[i];
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) ans += 1ll * abs(s[i]);
  printf("%lld\n", !sum ? ans : -1);
}
