#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<int> gra[MAXN], da[MAXN];
int d[MAXN];
queue<int> q;
int main() {
  int n, u, v, temd, ans, restn;
  scanf("%d", &n);
  for (int i = 1, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    gra[a].push_back(b);
    gra[b].push_back(a);
    d[a]++;
    d[b]++;
  }
  for (int i = 1; i <= n; ++i)
    if (d[i] == 1) q.push(i), da[i].push_back(0);
  restn = n;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    restn--;
    sort(da[u].begin(), da[u].end());
    da[u].erase(unique(da[u].begin(), da[u].end()), da[u].end());
    if (da[u].size() > 2 || da[u].size() == 2 && restn > 0) {
      u = -1;
      break;
    }
    temd = da[u].front() + 1;
    for (vector<int>::iterator iter = gra[u].begin(); iter != gra[u].end();
         ++iter)
      if (v = *iter, d[v] > 0) {
        da[v].push_back(temd);
        d[v]--;
        d[u]--;
        if (d[v] == 1) q.push(v);
      }
  }
  if (u < 0)
    printf("-1\n");
  else {
    ans = da[u][0] + da[u][1];
    while (ans % 2 == 0) ans /= 2;
    printf("%d\n", ans);
  }
  return 0;
}
