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;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
vector<int> A[300007];
int Node;
int Dfs1(int u, int pr) {
  map<int, int> mp;
  int vl = 0;
  int cnt = 0;
  for (int i = 0; i < A[u].size(); i++) {
    int v = A[u][i];
    if (v == pr) continue;
    int p = Dfs1(v, u);
    if (mp[p]) {
    } else {
      mp[p] = 1;
      cnt++;
      if (cnt == 2 && (u != Node)) {
        printf("-1\n");
        exit(0);
      } else if (cnt == 3) {
        printf("-1\n");
        exit(0);
      }
    }
    vl = p;
  }
  if (u == Node) {
    map<int, int>::iterator it;
    vector<int> P;
    for (it = mp.begin(); it != mp.end(); it++) {
      int vv = it->first;
      P.push_back(vv);
    }
    int val = P[0];
    if (P.size() > 1) val += P[1];
    while (val % 2 == 0) val /= 2;
    printf("%d\n", val);
    exit(0);
    if (P.size() == 1) {
      if ((P[0]) % 2)
        printf("%d\n", P[0]);
      else
        printf("%d\n", (P[0]) / 2);
    } else {
      if ((P[0] + P[1]) % 2)
        printf("%d\n", P[0] + P[1]);
      else
        printf("%d\n", (P[0] + P[1]) / 2);
    }
    exit(0);
  }
  vl++;
  return vl;
}
int Dfs(int u, int pr) {
  map<int, int> mp;
  int vl = 0;
  int cnt = 0;
  for (int i = 0; i < A[u].size(); i++) {
    int v = A[u][i];
    if (v == pr) continue;
    if (Node) continue;
    int p = Dfs(v, u);
    if (mp[p]) {
    } else {
      mp[p] = 1;
      cnt++;
      if (cnt > 1 && !Node) {
        Node = u;
        break;
      }
    }
    vl = p;
  }
  vl++;
  return vl;
}
int main() {
  int n;
  n = in<int>();
  for (int i = 1; i < n; i++) {
    int a, b;
    a = in<int>(), b = in<int>();
    A[a].push_back(b);
    A[b].push_back(a);
  }
  int vl = Dfs(1, 0);
  if (!Node) Node = 1;
  Dfs1(Node, 0);
  return 0;
}
