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 int inf = 0x7fffffff, infty = (int)1e9, mod = (int)1e9 + 7,
          dxy[] = {-1, 0, 1, 0, -1};
const long long INF = 1ll << 60;
const double pi = acos(-1), eps = 1e-8;
template <class T>
void rd(T &x) {
  x = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do x = x * 10 + (c ^ 48);
  while (c = getchar(), c > 47);
}
template <class T>
void pt(T x) {
  if (!x) {
    putchar('0');
    return;
  }
  static int stk[65];
  int tp = 0;
  for (; x; x /= 10) stk[tp++] = x % 10;
  for (int i = (tp)-1, _s = (0); i >= _s; --i) putchar(stk[i] ^ 48);
}
template <class T>
inline void pts(T x) {
  pt(x), putchar(' ');
}
template <class T>
inline void ptn(T x) {
  pt(x), putchar('\n');
}
template <class T>
inline void Max(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void Min(T &a, T b) {
  if (b < a) a = b;
}
const int N = (int)2e5 + 5;
int par[N], ID, mx_dist;
vector<int> T[N];
bool ban[N];
void dfs(int u, int pre, int dist) {
  if (dist >= mx_dist) {
    ID = u;
    mx_dist = dist;
  }
  par[u] = pre;
  for (int v : T[u]) {
    if (v == pre) continue;
    dfs(v, u, dist + 1);
  }
}
bool mark[N];
vector<int> calc(int u, int pre = 0) {
  vector<int> arr;
  for (int v : T[u]) {
    if (ban[v] || v == pre) continue;
    vector<int> tmp = calc(v, u);
    if (tmp[0] == -1 || ((int)(tmp).size()) > 1) return {-1};
    for (int elm : tmp) {
      arr.push_back(elm + 1);
      mark[elm + 1] = true;
    }
  }
  vector<int> res;
  for (int elm : arr)
    if (mark[elm]) {
      mark[elm] = false;
      res.push_back(elm);
    }
  if (res.empty()) return {0};
  if (((int)(res).size()) > 2) return {-1};
  return res;
}
int ans;
vector<int> rem[N];
bool check1() {
  for (int i = (0), _t = (mx_dist + 1); i < _t; ++i)
    for (int elm : rem[i]) {
      if (elm && elm != i && elm != mx_dist - i) return false;
    }
  ans = mx_dist;
  return true;
}
bool check2() {
  if (mx_dist & 1) return false;
  for (int i = (0), _t = (mx_dist + 1); i < _t; ++i) {
    if ((i << 1) == mx_dist) continue;
    for (int elm : rem[i]) {
      if (elm && elm != i && elm != mx_dist - i) return false;
    }
  }
  int cnt = 0;
  for (int elm : rem[mx_dist >> 1]) {
    if (!(elm && elm != (mx_dist >> 1))) continue;
    ++cnt;
  }
  if (cnt > 1) return false;
  ans = rem[mx_dist >> 1][0] + (mx_dist >> 1);
  return true;
}
int main() {
  int n;
  rd(n);
  for (int i = 1, u, v; i < n; ++i) {
    rd(u), rd(v);
    T[u].push_back(v);
    T[v].push_back(u);
  }
  mx_dist = 0;
  dfs(1, 0, 0);
  dfs(ID, 0, 0);
  for (int u = ID; u; u = par[u]) ban[u] = true;
  for (int u = ID, i = 0; u; u = par[u], ++i) {
    rem[i] = calc(u);
    if (rem[i][0] == -1) return puts("-1"), 0;
  }
  if (!check1() && !check2()) return puts("-1"), 0;
  while (~ans & 1) ans >>= 1;
  ptn(ans);
  return 0;
}
