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 Mn[MN], Mx[MN];
int n;
vector<int> adj[MN];
int Down_mn[MN], Down_mx[MN], Up_mx[MN], Up_mn[MN];
int good = -1;
int Dp[MN], dp[MN];
int My = INF;
void dfs_up(int s, int pr) {
  for (auto v : adj[s])
    if (v != pr) {
      dfs_up(v, s);
      Down_mx[s] = max(Down_mx[s], Down_mx[v] + 1);
      if (Down_mn[s] == 0)
        Down_mn[s] = Down_mn[v] + 1;
      else
        Down_mn[s] = min(Down_mn[s], Down_mn[v] + 1);
    }
}
void dfs_down(int s, int pr) {
  if (pr == -1) {
    Up_mx[s] = -INF;
    Up_mn[s] = INF;
  }
  int val = max(Down_mx[s], Up_mx[s]);
  if (val < My) My = val, good = s;
  Mn[0] = INF;
  for (int i = 0; i < ((int)(adj[s]).size()); ++i)
    if (adj[s][i] != pr) {
      Mx[i + 1] = max(Mx[i], Down_mx[adj[s][i]]);
      Mn[i + 1] = min(Mn[i], Down_mn[adj[s][i]]);
    } else
      Mn[i + 1] = Mn[i], Mx[i + 1] = Mx[i];
  int cur_mx = 0, cur_mn = INF;
  for (int i = ((int)(adj[s]).size()) - 1; ~i; --i)
    if (adj[s][i] != pr) {
      Up_mx[adj[s][i]] = max(Up_mx[s] + 1, max(Mx[i] + 2, cur_mx + 2));
      cur_mx = max(cur_mx, Down_mx[adj[s][i]]);
      Up_mn[adj[s][i]] = min(Up_mn[s] + 1, min(Mn[i] + 2, cur_mn + 2));
      cur_mn = min(cur_mn, Down_mn[adj[s][i]]);
    }
  for (int i = 0; i < ((int)(adj[s]).size()); ++i)
    if (adj[s][i] != pr) dfs_down(adj[s][i], s);
}
void fail() {
  cout << -1 << endl;
  exit(0);
}
void dfs(int s, int pr) {
  for (auto v : adj[s])
    if (v != pr) {
      dfs(v, s);
      Dp[s] = max(Dp[s], Dp[v] + 1);
      if (!dp[s])
        dp[s] = dp[v] + 1;
      else
        dp[s] = min(dp[s], dp[v] + 1);
    }
  if (~pr && Dp[s] != dp[s]) fail();
}
bool mk[MN];
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);
  }
  if (n == 2) {
    cout << 1 << '\n';
    return 0;
  }
  dfs_up(0, -1);
  dfs_down(0, -1);
  dfs(good, -1);
  int cnt = 0;
  for (auto v : adj[good])
    if (!mk[Dp[v]]) mk[Dp[v]] = true, ++cnt;
  if (cnt > 2) return cout << -1 << '\n', 0;
  int val = Dp[good] + dp[good];
  while (val % 2 == 0) val /= 2;
  cout << val << '\n';
  return 0;
}
