#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
long long ans;
vector<int> al[123456];
pair<int, int> go(int at, int fr) {
  int e = 0, o = 0;
  for (int to : al[at])
    if (to != fr) {
      pair<int, int> res = go(to, at);
      e += res.first;
      o += res.second;
    }
  swap(e, o);
  o++;
  if (e > o)
    e -= o, o = 0;
  else
    o -= e, e = 0;
  ans += o + e;
  return {e, o};
}
int main() {
  scanf("%d %d", &n, &m);
  assert(m == n - 1);
  for (int i = (0); i < (m); i++) {
    scanf("%d %d", &a, &b);
    al[a].push_back(b);
    al[b].push_back(a);
  }
  pair<int, int> res = go(1, 0);
  if (res.first || res.second) {
    puts("-1");
    return 0;
  }
  printf("%lld\n", ans);
  return 0;
}
