#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T = ll>
constexpr T TEN(int n) {
  return (n == 0) ? 1 : 10 * TEN<T>(n - 1);
}
const int MN = 100100;
int n;
vector<int> g[MN];
bool c[MN];
void dfs(int p, int b, bool cc = false) {
  c[p] = cc;
  for (int d : g[p]) {
    if (d == b) continue;
    dfs(d, p, !cc);
  }
}
int sz2[MN][2];
int dfs2(int p, int b) {
  int ans = 0;
  sz2[p][0] = sz2[p][1] = 0;
  sz2[p][c[p]]++;
  for (int d : g[p]) {
    if (d == b) continue;
    ans += dfs2(d, p);
    sz2[p][0] += sz2[d][0];
    sz2[p][1] += sz2[d][1];
  }
  return ans + abs(sz2[p][0] - sz2[p][1]);
}
int main() {
  int n, m;
  cin >> n >> m;
  assert(m == n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  int co[2] = {};
  for (int i = 0; i < n; i++) {
    co[c[i]]++;
  }
  if (co[0] != co[1]) {
    cout << -1 << endl;
    return 0;
  }
  cout << dfs2(0, -1) << endl;
  return 0;
}
