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