#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int N, M;
set<int> edge[100001];
set<int> check;
set<int>::iterator itr;
int s, e;
int ans;
bool flag[100001];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N - 1; i++) {
    cin >> s >> e;
    edge[s].insert(e);
    edge[e].insert(s);
  }
  if (N % 2) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if ((int)edge[i].size() == 1) {
      check.insert(i);
    }
  }
  while (!check.empty()) {
    itr = check.begin();
    flag[*itr] = true;
    flag[*edge[*itr].begin()] ^= true;
    edge[*edge[*itr].begin()].erase(*itr);
    if (edge[*edge[*itr].begin()].size() == 1) {
      check.insert(*edge[*itr].begin());
    }
    edge[*itr].clear();
    check.erase(*itr);
    N--;
    ans++;
    if (N == 1) break;
  }
  cout << ans << endl;
  return 0;
}
