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 = 1e9 + 10;
const int MN = 2e5 + 10;
int dp_up[MN], dp_down[MN], par[MN];
int Mx[MN], Mn[MN];
bool is[MN];
int n;
vector<int> adj[MN];
int ans = -1;
void dfs_up(int s, int pr) {
  par[s] = pr;
  int mx = -INF, mn = INF, cnt = 0;
  for (auto v : adj[s])
    if (v != pr) {
      ++cnt;
      dfs_up(v, s);
      if (dp_up[v] == -1) dp_up[s] = -1;
      if (dp_up[s] == -1) continue;
      mx = max(mx, dp_up[v]);
      mn = min(mn, dp_up[v]);
    }
  if (cnt == 0 || dp_up[s] == -1) return;
  if (mx != mn)
    dp_up[s] = -1;
  else
    dp_up[s] = mx + 1;
}
void dfs_down(int s, int pr) {
  Mn[0] = INF, Mx[0] = -INF, is[0] = false;
  for (int i = 0; i < ((int)(adj[s]).size()); ++i) {
    int v = adj[s][i];
    if (v == pr)
      Mx[i + 1] = Mx[i], Mn[i + 1] = Mn[i], is[i + 1] = is[i];
    else {
      Mx[i + 1] = max(Mx[i], dp_up[v] + 1);
      Mn[i + 1] = min(Mn[i], dp_up[v] + 1);
      is[i + 1] = (is[i] || (dp_up[v] == -1));
    }
  }
  int cur_mx = -INF, cur_mn = INF;
  bool cur_is = false;
  for (int i = ((int)(adj[s]).size()) - 1; ~i; --i) {
    int v = adj[s][i];
    if (v == pr) continue;
    if (dp_down[s] == -1) dp_down[v] = -1;
    if (cur_is || is[i]) dp_down[v] = -1;
    int my_mx = max(Mx[i], cur_mx);
    int my_mn = min(Mn[i], cur_mn);
    if (~pr) my_mn = min(my_mn, dp_down[s]), my_mx = max(my_mx, dp_down[s]);
    if (((int)(adj[s]).size()) == 1) {
      my_mn = min(my_mn, 0), my_mx = max(my_mx, 0);
    }
    if (my_mn != my_mx && ~dp_down[v]) dp_down[v] = -1;
    if (my_mn == my_mx && ~dp_down[v]) dp_down[v] = my_mn + 1;
    cur_mx = max(cur_mx, dp_up[v] + 1);
    cur_mn = min(cur_mn, dp_up[v] + 1);
    cur_is = cur_is || (dp_up[v] == -1);
  }
  for (auto v : adj[s])
    if (v != pr) dfs_down(v, s);
}
void upd(const vector<int>& vec) {
  int mx = -INF, mn = INF;
  for (auto x : vec) mn = min(mn, x), mx = max(mx, x);
  if (mn == -1) return;
  for (auto x : vec)
    if (x != mn && x != mx) return;
  int tmp = mn + mx;
  while (tmp % 2 == 0) tmp /= 2;
  ans = max(ans, tmp);
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].push_back(b), adj[b].push_back(a);
  }
  dfs_up(0, -1);
  dfs_down(0, -1);
  for (int i = 0; i < n; ++i) {
    vector<int> vec;
    vec.push_back(dp_down[i]);
    for (auto v : adj[i])
      if (v != par[i]) {
        if (~dp_up[v])
          vec.push_back(dp_up[v] + 1);
        else
          vec.push_back(-1);
      }
    upd(vec);
  }
  cout << ans << endl;
  return 0;
}
