10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
 10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
 4
4 1
4 3
4 2
 3
3 1
1 2
 9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
 5
1 5
2 3
2 4
1 2
 8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
 7
5 6
5 7
5 1
7 4
6 3
3 2
 3
1 3
3 2
 2
1 2
 5
5 4
4 3
3 1
5 2
 6
1 6
3 1
6 4
5 3
2 5
 11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
 11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
 12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5

-1
 9
 1
 1
 3
 3
 -1
 -1
 1
 1
 1
 5
 1
 5
 -1

#include <bits/stdc++.h>
using ull = unsigned long long int;
using ll = long long;
using ld = long double;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double>;
using vvd = std::vector<vd>;
using qi = std::queue<int>;
using vpii = std::vector<std::pair<int, int>>;
using vpll = std::vector<pll>;
using namespace std;
const int Mod = (1e9) + 7;
const int INF = 1e9 + 19;
const ll INFL = 1e18 + 19;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
const int dy2[] = {1, 0, -1, 1, 0, -1, 1, 0, -1};
const double EPS = 1e-10;
template <class T1, class T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
template <class T>
inline void pri(T a) {
  cout << a << endl;
}
template <class Z>
using vec = vector<Z>;
template <class T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T1, class T2>
void update(T1& a, T2 b) {
  a += b;
  if (a > Mod) a %= Mod;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest) {
  cin >> first;
  IN(rest...);
  return;
}
inline void OUT(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
  cout << first << " ";
  OUT(rest...);
  return;
}
bool pairsort(pll pl, pll pr) {
  if (pl.first == pr.first) return pl.second > pr.second;
  return pl.first < pr.first;
}
int cntbit(ll a, int n, int j) {
  int res = 0;
  for (int(i) = (j); (i) < (n); (i)++) {
    if (a >> i & 1) {
      res++;
    }
  }
  return res;
}
vector<int> make_bit(int a) {
  vector<int> res;
  for (int i = 31; i >= 0; i--)
    if (a & (1 << i)) res.push_back(i);
  return res;
}
bool stdbit(int a, int b) { return a & (1 << b); }
int GCD(int a, int b) {
  if (b > a) return GCD(b, a);
  if (a % b == 0)
    return b;
  else
    return GCD(b, a % b);
}
int LCM(int a, int b) { return a * b / GCD(a, b); }
int roundup(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return (a + b) / b;
}
int rounddown(int a, int b) {
  if (a % b == 0)
    return a / b;
  else {
    return (a - b) / b;
  }
}
ll pow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a *= a;
    n = n >> 1;
  }
  return res;
}
ll GetDiviserCount(ll N) {
  ll res = 1;
  for (int(i) = (2); (i) < (sqrt(N) + 1); (i)++) {
    ll cnt = 0;
    while (N % i == 0) {
      cnt++;
      N /= i;
    }
    res *= (cnt + 1);
    if (N == 1) break;
  }
  if (N != 1) res *= 2;
  return res;
}
vll GetDivisor(ll N) {
  vll res;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      if (i * i != N) res.push_back(N / i);
    }
  }
  sort((res).begin(), (res).end());
  return res;
}
struct mint {
  ll x;
  mint(ll x = 0) : x((x % Mod + Mod) % Mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += Mod - a.x) >= Mod) x -= Mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= Mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(Mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream& operator<<(ostream& os, const mint& a);
};
ostream& operator<<(ostream& os, const mint& a) {
  os << a.x;
  return os;
}
using vm = vector<mint>;
using vvm = vector<vm>;
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < Mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
template <class Z>
struct MyMatrix {
  using mat = MyMatrix<Z>;
  vector<vector<Z>> m_dat;
  int m_h;
  int m_w;
  MyMatrix(int h, int w) : m_h(h), m_w(w), m_dat(h, vector<Z>(w)) {}
  vector<Z>& operator[](int idx) { return m_dat[idx]; }
  mat Multiple(mat& a) {
    mat C(m_h, a.m_w);
    for (int i = 0; i < m_h; i++) {
      for (int j = 0; j < a.m_w; j++) {
        for (int k = 0; k < m_w; k++) {
          C[i][j] += m_dat[i][k] * a[k][j];
        }
      }
    }
    return C;
  }
  mat Pow(ll x) {
    mat B(m_h, m_w);
    for (int i = 0; i < m_h; i++) {
      B[i][i] = 1;
    }
    mat A = *this;
    while (x > 0) {
      if (x & 1) B = B.Multiple(A);
      A = A.Multiple(A);
      x = x >> 1;
    }
    return B;
  }
};
template <class T>
using mat = MyMatrix<T>;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
int n, m, k;
ll N;
int h, w;
string S;
int a, b, c;
vi v;
double x, y, z;
vector<int> G[1010101];
int ans = INF;
bool whi = false;
struct Data {
  bool ok = 1;
  int ng = 0;
  int NodeNum = 1;
  map<int, int> mp;
  Data() {}
  Data(int NodeNum, int ng, bool ok) : NodeNum(NodeNum), ng(ng), ok(ok) {}
};
vector<Data> dp;
void dfs(int curr, int last = -1) {
  for (auto(to) : (G[curr])) {
    if (to == last) continue;
    dfs(to, curr);
    dp[curr].NodeNum += dp[to].NodeNum;
    if (!dp[to].ok) {
      dp[curr].ng++;
    } else {
      if (dp[curr].mp.find(dp[to].NodeNum) != dp[curr].mp.end()) {
        whi = true;
        dp[curr].mp[dp[to].NodeNum] += 1;
        dp[curr].NodeNum -= dp[to].NodeNum;
      } else {
        dp[curr].mp[dp[to].NodeNum] = 1;
      }
    }
  }
  if (dp[curr].mp.size() > 1 or dp[curr].ng > 0)
    dp[curr].ok = false;
  else
    dp[curr].ok = true;
}
void ndfs(int curr, int last = -1, int Num = 0, bool ok = true) {
  if (last == -1) {
    for (auto(to) : (G[curr])) {
      bool ok2;
      if (!dp[to].ok) {
        if (dp[curr].ng == 1 and dp[curr].mp.size() == 1)
          ok2 = true;
        else
          ok2 = false;
        ndfs(to, curr, dp[curr].NodeNum - dp[to].NodeNum, ok2);
      } else {
        if (dp[curr].mp.size() == 1 and dp[curr].ng == 0)
          ok2 = true;
        else
          ok2 = false;
        int dist;
        if (dp[curr].mp[dp[to].NodeNum] > 1)
          dist = dp[curr].NodeNum;
        else
          dist = dp[curr].NodeNum - dp[to].NodeNum;
        ndfs(to, curr, dist, ok2);
      }
    }
    chmin(ans, dp[curr].NodeNum);
  } else {
    if (ok) {
      if (dp[curr].mp.find(Num) != dp[curr].mp.end()) {
        whi = true;
        dp[curr].mp[Num] += 1;
      } else {
        dp[curr].ok = false;
        dp[curr].mp[Num] = 1;
        dp[curr].NodeNum += Num;
      }
    } else {
      dp[curr].ok = false;
      dp[curr].ng++;
      dp[curr].NodeNum += Num;
    }
  }
  for (auto(to) : (G[curr])) {
    if (to == last) continue;
    bool ok2;
    if (!dp[to].ok) {
      if (dp[curr].ng == 1 and dp[curr].mp.size() == 1)
        ok2 = true;
      else
        ok2 = false;
      ndfs(to, curr, dp[curr].NodeNum - dp[to].NodeNum, ok2);
    } else {
      if (dp[curr].mp.size() == 1 and dp[curr].ng == 0)
        ok2 = true;
      else
        ok2 = false;
      int dist;
      if (dp[curr].mp[dp[to].NodeNum] > 1)
        dist = dp[curr].NodeNum;
      else
        dist = dp[curr].NodeNum - dp[to].NodeNum;
      ndfs(to, curr, dist, ok2);
    }
  }
  chmin(ans, dp[curr].NodeNum);
}
signed main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(n);
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    IN(a, b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dp = vector<Data>(n + 1, Data(1, 0, 1));
  dfs(0);
  ndfs(0);
  if (!whi)
    ans = -1;
  else
    ans--;
  pri(ans);
  return 0;
}
