#include <bits/stdc++.h>
using namespace std;
template <class T>
T smin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
const int N = (int)(1e6) + 5;
vector<int> g[N];
int deg[N];
int d[N];
int main(void) {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    ++deg[a];
    ++deg[b];
  }
  for (int i = 1; i <= n; ++i) d[i] = 1;
  set<pair<int, int> > ss;
  for (int i = 1; i <= n; ++i) ss.insert(make_pair(deg[i], i));
  int ans = 0;
  while (ss.size() > 1) {
    int node = ss.begin()->second;
    ss.erase(ss.begin());
    ans += d[node];
    for (auto it : g[node])
      if (deg[it]) {
        d[it] ^= d[node];
        ss.erase(make_pair(deg[it], it));
        --deg[it];
        ss.insert(make_pair(deg[it], it));
      }
    d[node] = 0;
    deg[node] = 0;
  }
  for (int i = 1; i <= n; ++i)
    if (d[i]) return puts("-1") * 0;
  cout << ans << '\n';
  return 0;
}
