#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;
}
