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;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) { return n | (1LL << i); }
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline double dist(double ix, double iy, double jx, double jy) {
  return sqrt(((ix - jx) * (ix - jx)) + ((iy - jy) * (iy - jy)));
}
int marked[1000000 / 64 + 2];
bool isPrime(int x) {
  return (x > 1) &&
         ((x == 2) ||
          ((x & 1) && (!((marked[x >> 6] & (1 << ((x & 63) >> 1)))))));
}
void seive(int n) {
  int i, j;
  for (i = 3; i * i <= n; i += 2) {
    if (!(marked[i >> 6] & (1 << ((i & 63) >> 1)))) {
      for (j = i * i; j <= n; j += i << 1) {
        marked[j >> 6] |= (1 << ((j & 63) >> 1));
      }
    }
  }
}
long long bigMod(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) (r *= a) %= 1000000007;
    b >>= 1;
    (a *= a) %= 1000000007;
  }
  return r;
}
long long add(long long a, long long b) {
  long long ret = a + b;
  if (ret >= 1000000007) ret -= 1000000007;
  return ret;
}
long long sub(long long a, long long b) {
  long long ret = a - b;
  if (ret < 0) ret += 1000000007;
  return ret;
}
vector<int> edge[200007];
int a, b, c, mx[200007];
set<int> ss[5];
int dfs(int i, int pre = -1) {
  int ret = i;
  for (auto u : edge[i]) {
    if (u == pre) continue;
    ret = dfs(u, i);
  }
  return ret;
}
int dodp(int i, int pre = -1) {
  int ret = 0, now = 0;
  for (auto u : edge[i]) {
    if (u == pre) continue;
    int p = dodp(u, i);
    if (ret < p) {
      now = u;
      ret = p;
    }
  }
  mx[i] = now;
  return ret + 1;
}
int dfs2(int i, int pre = -1, int so = 0) {
  int ret = 0;
  if (mx[i]) ret = dfs2(mx[i], i, so + 1);
  if (so == ret)
    a = i;
  else if (so + 1 == ret)
    b = i;
  else if (so == ret + 1)
    c = i;
  return ret + 1;
}
int dfs3(int i, int even, int pre = -1) {
  ;
  set<int> s;
  int ret = 0;
  for (auto u : edge[i]) {
    if (u == pre) continue;
    int p = dfs3(u, -1, i);
    if (p == -1) return -1;
    s.insert(p);
  }
  if (even != -1) {
    if (s.size() > 2) return -1;
    ss[even] = s;
    ;
  } else if (s.size() > 1)
    return -1;
  if (s.size()) ret = *(s.begin());
  return ret + 1;
}
int main() {
  int n, i, u, v, p, ans, s2, s3;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  p = dfs(1);
  dodp(p);
  dfs2(p);
  if (a) {
    p = dfs3(a, 1);
    if (p == -1)
      ans = p;
    else {
      auto it = ss[1].begin();
      a = 0;
      while (it != ss[1].end()) {
        a += *it;
        it++;
      }
      while (a % 2 == 0) a /= 2;
      ans = a;
    }
  } else {
    set<int> s;
    p = dfs3(b, 2, c);
    if (p == -1)
      ans = p;
    else {
      p = dfs3(c, 3, b);
      if (p == -1)
        ans = p;
      else {
        s2 = ss[2].size();
        s3 = ss[3].size();
        if (s2 + s3 == 2) {
          b = *(ss[2].begin()) + *(ss[3].begin());
          while (b % 2 == 0) b /= 2;
          ans = b;
        } else
          ans = -1;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
