#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
vector<long long> g[N];
long long black[N], white[N], ans;
void dfs(long long v, long long p, long long curh) {
  if (curh & 1) {
    black[v] = 1;
  } else {
    white[v] = 1;
  }
  for (auto u : g[v]) {
    if (u != p) {
      dfs(u, v, curh + 1);
      black[v] += black[u];
      white[v] += white[u];
      ans += abs(black[u] - white[u]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  if (m == n - 1) {
    for (long long i = 1; i < n; i++) {
      long long u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0, 0);
    if (white[1] == black[1]) {
      cout << ans << '\n';
    } else {
      cout << -1 << '\n';
    }
  }
}
