#include <bits/stdc++.h>
using namespace std;
const pair<int, int> DD[] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                             {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
template <class T>
T smin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  int n;
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  static vector<int> s[1 << 20];
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    s[a].push_back(b);
    s[b].push_back(a);
  }
  static int H[1 << 20];
  static int ok1[1 << 20];
  static int h[1 << 20];
  function<void(int, int)> dfs1 = [&](int node, int prev) {
    set<int> ss;
    ok1[node] = 1;
    for (auto it : s[node])
      if (it != prev)
        dfs1(it, node), ok1[node] &= ok1[it], ss.insert(H[it] + 1);
    ok1[node] &= ss.size() <= 1;
    for (auto it : ss) H[node] += it;
  };
  dfs1(1, 0);
  static int ans[1 << 20];
  for (int i = 1; i <= n; ++i) ans[i] = 2e9;
  function<void(int, int, int)> dfs2 = [&](int node, int prev, int offset) {
    set<int> ss;
    map<int, int> M;
    auto ADD = [&](int number, int v) {
      M[number] += v;
      if (!M[number]) M.erase(M.find(number));
    };
    if (offset != -1) ADD(offset + 1, 1);
    int was = 0;
    int was_ok = 0;
    for (auto it : s[node])
      if (it != prev) {
        ADD(H[it] + 1, 1);
        ++was;
        was_ok += ok1[it];
      }
    if (was_ok == was && M.size() <= 2) {
      ans[node] = 0;
      for (auto it : M) ans[node] += it.first;
      while (!(ans[node] & 1)) ans[node] /= 2;
    }
    for (auto it : s[node])
      if (it != prev) {
        ADD(H[it] + 1, -1);
        int next_ok = M.size() <= 1 && (was - 1 == was_ok - ok1[it]);
        int next_offset = 0;
        if (next_ok) {
          for (auto it : M) next_offset += it.first;
          if (M.empty()) next_offset = offset + 1;
          dfs2(it, node, next_offset);
        }
        ADD(H[it] + 1, 1);
      }
  };
  dfs2(1, 0, -1);
  int answer = *min_element(ans + 1, ans + 1 + n);
  if (answer <= n)
    cout << answer << '\n';
  else
    puts("-1");
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
