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;
using namespace std;
int inp;
void sc(long long &x) {
  scanf("%d", &inp);
  x = inp;
}
void sc(long long &x, long long &y) {
  scanf("%d", &inp);
  x = inp;
  scanf("%d", &inp);
  y = inp;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void setbit(int &m, int ind, int val) {
  if (val)
    m = (m | (1 << ind));
  else
    m = (m & ~(1 << ind));
}
bool getbit(int m, int ind) {
  int a = (1 << ind);
  a = (a & m);
  return a;
}
int cntbits(int m) {
  int ret = 0;
  while (m) {
    ret += (m % 2);
    m /= 2;
  }
  return ret;
}
bool smlltr(char c) {
  if (c >= 'a' && c <= 'z') return 1;
  return 0;
}
bool capltr(char c) {
  if (c >= 'A' && c <= 'Z') return 1;
  return 0;
}
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
const long long mod3 = 1e9 + 9;
long long pow_mod(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return (a * pow_mod((a * a) % mod, b / 2)) % mod;
  return pow_mod((a * a) % mod, b / 2);
}
int n, m, tmp, x, y, z, sol, maxi, mini, sum, side1, side2, p[200100], c,
    dist[200100], lngst[200100];
bool vis[200100];
vector<int> v[200100];
void dfs(int node) {
  vis[node] = 1;
  lngst[node] = 1;
  for (int i = 0; i <= v[node].size() - 1; i++) {
    int son = v[node][i];
    if (vis[son] == 0) {
      dist[son] = dist[node] + 1;
      p[son] = node;
      dfs(son);
      lngst[node] = max(lngst[node], lngst[son] + 1);
    }
  }
}
int check(int root) {
  for (int node = 1; node <= n; node++)
    if (node != root) {
      for (int i = 0; i < v[node].size(); i++) {
        int son = v[node][i];
        if (dist[son] == dist[node] + 1 && lngst[son] != lngst[node] - 1)
          return -1;
      }
    }
  vector<int> tmpv;
  tmpv.clear();
  for (int i = 0; i < v[root].size(); i++) {
    int son = v[root][i];
    tmpv.push_back(lngst[son]);
  }
  if (tmpv.size() == 1) {
    return tmpv[0] + 1;
  } else if (tmpv.size() == 2) {
    if (tmpv[0] == tmpv[1])
      return tmpv[0] + 1;
    else
      return tmpv[0] + tmpv[1] + 1;
  } else {
    sort(tmpv.begin(), tmpv.end());
    vector<int> tmppv;
    tmppv.clear();
    int cnttt = 0;
    tmppv.push_back(tmpv[0]);
    for (int i = 1; i <= tmpv.size() - 1; i++)
      if (tmpv[i] != tmpv[i - 1]) {
        cnttt++;
        tmppv.push_back(tmpv[i]);
      }
    if (cnttt > 1)
      return -1;
    else {
      if (tmppv.size() == 1) tmppv.push_back(tmppv[0]);
      int xxx = tmppv[0], yyy = tmppv[1];
      return xxx + yyy + 1;
    }
  }
}
void prnt() {
  for (int i = 1; i <= n; i++)
    cout << i << ": " << p[i] << " " << dist[i] << " " << lngst[i] << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    {
      v[x].push_back(y);
      v[y].push_back(x);
    };
  }
  dfs(1);
  maxi = 0;
  for (int i = 1; i <= n; i++)
    if (dist[i] > maxi) {
      maxi = dist[i];
      side1 = i;
    }
  memset(dist, 0, sizeof(dist));
  memset(p, 0, sizeof(p));
  memset(lngst, 0, sizeof(lngst));
  memset(vis, 0, sizeof(vis));
  dfs(side1);
  maxi = 0;
  for (int i = 1; i <= n; i++)
    if (dist[i] > maxi) {
      maxi = dist[i];
      side2 = i;
    }
  memset(dist, 0, sizeof(dist));
  memset(p, 0, sizeof(p));
  memset(lngst, 0, sizeof(lngst));
  memset(vis, 0, sizeof(vis));
  dfs(side1);
  tmp = dist[side2];
  tmp /= 2;
  for (int i = 1; i <= tmp; i++) side2 = p[side2];
  c = side2;
  memset(dist, 0, sizeof(dist));
  memset(p, 0, sizeof(p));
  memset(lngst, 0, sizeof(lngst));
  memset(vis, 0, sizeof(vis));
  dfs(c);
  int lol = check(c);
  if (lol == -1)
    cout << lol;
  else {
    tmp = lol - 1;
    while (tmp % 2 == 0) tmp /= 2;
    cout << tmp;
  }
  return 0;
}
