#include <bits/stdc++.h>
using namespace std;
vector<long long> w[120001];
long long n, m, s, cnt[120001], sz[120001];
long long dfs(long long u, long long p, long long dep) {
  if (dep & 1) s++, cnt[u]++;
  sz[u] = 1;
  for (long long v : w[u])
    if (v != p) cnt[u] += dfs(v, u, dep + 1), sz[u] += sz[v];
  return cnt[u];
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i < n; i++) {
    long long u, v;
    scanf("%lld%lld", &u, &v);
    w[u].push_back(v);
    w[v].push_back(u);
  }
  dfs(1, 0, 0);
  if (s * 2 != n) {
    puts("-1");
    return 0;
  }
  long long ans = 0;
  for (long long i = 2; i <= n; i++) ans += abs(sz[i] - 2 * cnt[i]);
  cout << ans << endl;
  return 0;
}
