#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
vector<int> v[maxn];
long long ans = 0;
pair<int, int> dfs(int u, int h = 0, int par = -1) {
  int cnt[2] = {0, 0};
  for (int y : v[u]) {
    if (y != par) {
      pair<int, int> p = dfs(y, h + 1, u);
      cnt[p.second] += p.first;
      ans += p.first;
    }
  }
  cnt[h & 1]++;
  int mn = min(cnt[0], cnt[1]);
  cnt[0] -= mn, cnt[1] -= mn;
  if (cnt[1] != 0)
    return {cnt[1], 1};
  else
    return {cnt[0], 0};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie();
  int n, m;
  cin >> n >> m;
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  if (dfs(1).first != 0) return cout << -1 << endl, 0;
  return cout << ans << endl, 0;
}
