#include <bits/stdc++.h>
using namespace std;
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  return os << "(" << v.first << ", " << v.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T>
bool setmax(T& _a, T _b) {
  if (_b > _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
bool setmin(T& _a, T _b) {
  if (_b < _a) {
    _a = _b;
    return true;
  }
  return false;
}
template <class T>
T gcd(T _a, T _b) {
  return _b == 0 ? _a : gcd(_b, _a % _b);
}
const int N = 100010;
const int INF = 1 << 28;
vector<int> es[N];
int n, ans;
int dfs(int x, int fa) {
  int r = 1;
  for (int y : es[x])
    if (y != fa) {
      const auto tmp = dfs(y, x);
      ans += abs(tmp);
      r -= tmp;
    }
  return r;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  if (m != n - 1) return 0;
  for (int i = int(1); i <= int(n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    es[a].push_back(b), es[b].push_back(a);
  }
  ans = 0;
  if (dfs(1, 0) != 0)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
