#include <bits/stdc++.h>
using namespace std;
namespace case1 {
const int maxn = 100005;
vector<int> e[maxn];
int a, b, ans;
int dfs(int u, int fa, int col) {
  int res = col, tmp;
  for (int i = (0); i <= int(e[u].size() - 1); ++i)
    if (e[u][i] != fa) {
      tmp = dfs(e[u][i], u, -col);
      res += tmp;
      ans += abs(tmp);
    }
  return res;
}
void solve(int n) {
  for (int i = (1); i <= int(n - 1); ++i) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  if (dfs(1, 0, 1))
    puts("-1");
  else
    printf("%d\n", ans);
}
}  // namespace case1
namespace case2 {
void solve(int n) {}
}  // namespace case2
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == n - 1)
    case1::solve(n);
  else
    case2::solve(n);
  return 0;
}
