#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const long long INF = 1e18;
long long power(long long x, long long y) {
  long long t = 1;
  while (y > 0) {
    if (y % 2)
      y -= 1, t = t * x % mod;
    else
      y /= 2, x = x * x % mod;
  }
  return t;
}
vector<int> G[N], hts[N];
int ans = mod, dep[N], fl[N];
int my[N];
void dfs(int v, int p, int d = 0) {
  dep[v] = d;
  int ct = 0;
  fl[v] = 1;
  for (int i = 0; i < G[v].size(); ++i)
    if (G[v][i] != p) {
      ct++;
      int to = G[v][i];
      dfs(to, v, d + 1);
      if (fl[to] == 0 || hts[to].size() > 1) {
        fl[v] = 0;
      } else {
        hts[v].push_back(hts[to][0] + 1);
      }
    }
  if (ct == 0) {
    hts[v].push_back(0);
  }
  sort(hts[v].begin(), hts[v].end());
  hts[v].resize(unique(hts[v].begin(), hts[v].end()) - hts[v].begin());
  if (hts[v].size() > 2) fl[v] = 0;
}
void dfs1(int v, int p, int h) {
  vector<int> lol = hts[v];
  if (h == -1) return;
  if (p != -1) {
    lol.push_back(h);
    sort(lol.begin(), lol.end());
    lol.resize(unique(lol.begin(), lol.end()) - lol.begin());
  }
  if (fl[v] && lol.size() <= 2) {
    int a = 0;
    for (int i = 0; i < lol.size(); ++i) a += lol[i];
    while (a % 2 == 0) a /= 2;
    ans = min(ans, a);
  }
  if (lol.size() > 2) return;
  int ct[2];
  memset(ct, 0, sizeof(ct));
  if (p != -1) {
    for (int i = 0; i < lol.size(); ++i)
      if (lol[i] == h) ct[i]++;
  }
  int bad = 0;
  for (int i = 0; i < G[v].size(); ++i)
    if (G[v][i] != p) {
      int to = G[v][i];
      if (fl[to] == 0 || hts[to].size() > 1) {
        bad++;
      } else {
        for (int j = 0; j < lol.size(); ++j)
          if (lol[j] == hts[to][0] + 1) ct[j]++;
      }
    }
  for (int i = 0; i < G[v].size(); ++i)
    if (G[v][i] != p) {
      int to = G[v][i];
      if (fl[to] == 0 || hts[to].size() > 1) {
        bad--;
      } else {
        for (int j = 0; j < lol.size(); ++j)
          if (lol[j] == hts[to][0] + 1) ct[j]--;
      }
      int cp = -1;
      if (bad || (ct[0] && ct[1])) {
        ;
      } else {
        cp = 1;
        for (int i = 0; i < lol.size(); ++i)
          if (ct[i]) {
            cp = lol[i] + 1;
          }
      }
      if (cp != -1) dfs1(to, v, cp);
      if (fl[to] == 0 || hts[to].size() > 1) {
        bad++;
      } else {
        for (int j = 0; j < lol.size(); ++j)
          if (lol[j] == hts[to][0] + 1) ct[j]++;
      }
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0, -1);
  dfs1(0, -1, 0);
  if (ans == mod)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
