#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const int N = 200000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000010;
const long long LOG = 25;
int n, m, E, O, h[N], par[N], vaz[N], ans;
vector<int> G[N];
void DFS(int v = 1, int p = 0) {
  if (h[v] % 2 == 0)
    E++;
  else
    O++;
  for (auto u : G[v]) {
    if (u == p) continue;
    h[u] = h[v] + 1;
    par[u] = v;
    DFS(u, v);
  }
  if (vaz[v] == 0) vaz[v] = 1, vaz[p] ^= 1, ans++;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (m == n) assert(0);
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  DFS(1);
  if (O % 2 != E % 2) return cout << -1, 0;
  assert(0);
  return 0;
}
