%:pragma GCC optimize("Ofast")
  %:pragma GCC optimize("inline")
#include <bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
#define pb push_back
const int N = 3e5 + 233;
int n, m, col[N], ans = 0;
vector <int> g[N];

inline int dfs(int u, int fat) {
  for (auto v : g[u]) if (v != fat) {
      if (dfs(v, u)) {
        ++ ans;
        col[u] ^= 1;
      }
    }
  return !col[u];
}

main(void) {
  read(n); read(m);
  assert(n - 1 == m);
  for (int i = 2; i <= n; i ++) {
    int x, y; read(x); read(y);
    g[x].pb(y); g[y].pb(x);
  }
  if (dfs(1, 0)) cout << "-1\n";
  else
    cout << ans << "\n";
}
