#include <bits/stdc++.h>
using namespace std;
const int N = 20000 + 10;
int n, m;
vector<int> g[N];
int sz[N];
void dfs(int u, int p) {
  sz[u] = 1;
  for (auto v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 1);
  int res = 0;
  for (int i = 1; i <= n; i++)
    if (sz[i] % 2) res++;
  if (sz[1] % 2) res = -1;
  printf("%d\n", res);
}
