#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long LINF = 4e18;
const long long delta = 10067;
const int N = 1e5 + 20;
vector<int> G[N];
int n, m, cnt[N], sz[N], ans;
void dfs(int v, int p = -1, int c = 0) {
  cnt[v] = c;
  sz[v] = 1;
  for (int u : G[v])
    if (u - p) dfs(u, v, 1 - c), cnt[v] += cnt[u], sz[v] += sz[u];
  ans += (cnt[v] != sz[v] - cnt[v]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0, v, u; i < n - 1; i++) {
    cin >> v >> u;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  dfs(1);
  if (cnt[1] != n - cnt[1])
    cout << -1 << endl;
  else
    cout << ans << endl;
}
