#include <bits/stdc++.h>
using namespace std;
int n, m, ans, a[100010];
int cnt, head[100010], to[200010], nxt[200010];
void add(int x, int y) {
  cnt++;
  to[cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
void dfs1(int x, int fa) {
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa) {
      continue;
    }
    dfs1(y, x);
    if (!a[y]) {
      a[x] ^= 1;
      ans++;
    }
  }
}
void solve1() {
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs1(1, 0);
  if (!a[1]) {
    puts("-1");
  } else {
    cout << ans << endl;
  }
}
void solve2() { assert(false); }
int main() {
  scanf("%d%d", &n, &m);
  if (n == m + 1) {
    solve1();
  } else {
    solve2();
  }
  return 0;
}
