#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
int n, m;
vector<int> g[100005];
void ng() {
  puts("-1");
  exit(0);
}
pair<int, int> dfs(int v, int p) {
  int cost = 0, sign = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    pair<int, int> nxt = dfs(to, v);
    cost += nxt.first;
    sign ^= nxt.second;
  }
  if (sign == 0)
    return make_pair(cost + 1, 1);
  else
    return make_pair(cost, 0);
}
void solve1() {
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  pair<int, int> res = dfs(0, -1);
  if (res.second == 1) ng();
  printf("%d\n", res.first);
}
int main() {
  cin >> n >> m;
  if (n & 1) ng();
  if (m == n - 1) solve1();
  return 0;
}
