#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
template <typename Iter>
ostream &_IterOutput_(ostream &o, Iter b, Iter e, const string ss = "",
                      const string se = "") {
  o << ss;
  for (auto it = b; it != e; it++) o << (it == b ? "" : ", ") << *it;
  return o << se;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &pair) {
  return o << "(" << pair.first << ", " << pair.second << ")";
}
template <typename T>
ostream &operator<<(ostream &o, const vector<T> &vec) {
  return _IterOutput_(o, begin(vec), end(vec), "[", "]");
}
template <typename T>
ostream &operator<<(ostream &o, const set<T> &st) {
  return _IterOutput_(o, begin(st), end(st), "{", "}");
}
template <typename T, size_t N>
ostream &operator<<(ostream &o, const array<T, N> &arr) {
  return _IterOutput_(o, begin(arr), end(arr), "|", "|");
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &mp) {
  o << "{";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    o << (it == mp.begin() ? "" : ", ") << it->first << ":" << it->second;
  }
  o << "}";
  return o;
}
const long long MX = 101010;
long long V, E;
using pii = pair<long long, long long>;
vector<long long> el[MX];
long long ans;
pii dfs(long long u, long long fa) {
  pii p = {0, 0};
  for (auto v : el[u]) {
    if (v == fa) continue;
    auto q = dfs(v, u);
    p.first += q.first;
    p.second += q.second;
  }
  if (p.first == p.second + 1) {
    return {0, 0};
  } else if (p.first <= p.second) {
    long long t = p.second - p.first + 1;
    ans += t;
    return {t, 0};
  } else {
    long long t = p.first - p.second - 1;
    ans += t;
    return {0, t};
  }
}
int32_t main() {
  do {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  } while (0);
  cin >> V >> E;
  if (E != V - 1) return 0;
  for (long long i = 0; i < E; i++) {
    long long u, v;
    cin >> u >> v;
    el[u].push_back(v);
    el[v].push_back(u);
  }
  auto p = dfs(1, 0);
  if (p != pii(0, 0)) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
