#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 500;
int dp[N], sol = 0, n, m;
vector<int> v[N];
void dfs(int x, int lst) {
  dp[x] = 1;
  for (int y : v[x]) {
    if (y == lst) continue;
    dfs(y, x);
    dp[x] += dp[y];
  }
  sol += dp[x] % 2;
}
int main() {
  scanf("%d%d", &n, &m);
  if ((n & 1) || n == m) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y), v[y].push_back(x);
  }
  dfs(1, 1);
  printf("%d\n", sol);
  return 0;
}
