#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, siz = 1e6 + 5;
vector<long long> g[siz];
long long t, n, m, k, a[siz], node, dep[siz];
long long go(long long u, long long p) {
  set<long long> have;
  for (auto v : g[u]) {
    if (v == p) continue;
    long long got = go(v, u);
    if (got == -1) return -1;
    have.insert(got + 1);
  }
  if (have.size() == 0) return 0;
  if (have.size() == 1) return *have.begin();
  if (have.size() == 2 and p == 0) return *have.begin() + *have.rbegin();
  node = u;
  return -1;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long ans = go(1, 0);
  if (ans == -1) {
    ans = go(node, 0);
  }
  while (ans % 2 == 0) ans /= 2;
  cout << ans << endl;
}
