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 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;
}
