#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const long long N = 2e5 + 100;
vector<long long> g[N];
long long long long b[N], w[N];
long long long long dfs(long long long long v, long long long long p,
                        long long long long h) {
  if (h % 2 == 1)
    b[v]++;
  else
    w[v]++;
  for (auto u : g[v]) {
    if (u == p) continue;
    dfs(u, v, h + 1);
    b[v] += b[u];
    w[v] += w[u];
  }
}
int32_t main() {
  long long long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n; i++) {
    long long long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 1, 1);
  if (w[1] != b[1]) return cout << -1 << '\n', 0;
  ;
  long long long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += abs(w[i] - b[i]);
  }
  cout << ans << '\n';
}
