#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int N, M;
list<int> edge[100001];
int s, e;
int ans;
int main() {
  cin >> N >> M;
  for (int i = 0; i < N - 1; i++) {
    cin >> s >> e;
    edge[s].push_back(e);
    edge[e].push_back(s);
  }
  if (N % 2) {
    cout << "-1\n";
    return 0;
  }
  ans = N / 2;
  for (int i = 1; i <= N; i++) {
    ans += ((int)edge[i].size() - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}
