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