#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
template <typename T>
inline T read() {
  T x(0), f(1);
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
  return x * f;
}
int e, st[MAXN], to[MAXN << 1];
int nxt[MAXN << 1], size[MAXN];
inline void Add(int u, int v) {
  to[++e] = v, nxt[e] = st[u];
  st[u] = e;
}
int n, m, ans, ans1, ans2;
int dfs(int u, int fa, int dep) {
  int res = dep & 1 ? 1 : 0;
  if (dep & 1)
    ans1++;
  else
    ans2++;
  size[u] = 1;
  for (int i = st[u]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    res += dfs(to[i], u, dep + 1);
    size[u] += size[to[i]];
  }
  if (u != 1) {
    ans += abs(size[u] - (res << 1));
  }
  return res;
}
int main() {
  n = read<int>(), m = read<int>();
  if (m == n - 1) {
    for (int i = 1; i < n; i++) {
      int u = read<int>(), v = read<int>();
      Add(u, v), Add(v, u);
    }
    dfs(1, 1, 1);
    if (ans1 == ans2)
      printf("%d\n", ans);
    else
      printf("-1\n");
  } else {
    while (true) {
    }
  }
  return 0;
}
