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>
int32_t shorten(int32_t n) {
  while (n % 2 == 0) n /= 2;
  return n;
}
int main() {
  int32_t n;
  std::cin >> n;
  std::vector<int32_t>* tree = new std::vector<int32_t>[n];
  for (int32_t i = 0; i < n - 1; i++) {
    int32_t src, dst;
    std::cin >> src >> dst;
    src--;
    dst--;
    tree[src].push_back(dst);
    tree[dst].push_back(src);
  }
  int32_t* bucket_id = new int32_t[n];
  int32_t* remains = new int32_t[n];
  std::queue<int32_t> queue;
  for (int32_t i = 0; i < n; i++) {
    remains[i] = tree[i].size();
    if (tree[i].size() == 1) {
      bucket_id[i] = 0;
      queue.emplace(i);
    } else
      bucket_id[i] = INT32_MAX;
  }
  while (!queue.empty()) {
    int32_t cur = queue.front();
    queue.pop();
    for (int32_t i = 0; i < tree[cur].size(); i++)
      if (bucket_id[tree[cur][i]] == INT32_MAX) {
        remains[tree[cur][i]]--;
        if (remains[tree[cur][i]] == 1) {
          int32_t prev_max = 0;
          for (int32_t j = 0; j < tree[tree[cur][i]].size(); j++) {
            if (bucket_id[tree[tree[cur][i]][j]] != INT32_MAX)
              prev_max = std::max(prev_max, bucket_id[tree[tree[cur][i]][j]]);
          }
          bucket_id[tree[cur][i]] = prev_max + 1;
          queue.push(tree[cur][i]);
        }
      }
  }
  int32_t* order = new int32_t[n];
  for (int32_t i = 0; i < n; i++) order[i] = i;
  std::sort(order, order + n, [bucket_id](int32_t v1, int32_t v2) {
    return bucket_id[v1] < bucket_id[v2];
  });
  int32_t* bamboo_lengths = new int32_t[n];
  for (int32_t i = 0; i < n; i++) bamboo_lengths[i] = -1;
  for (int32_t i = 0; i < n; i++) {
    if (tree[order[i]].size() == 1) {
      bamboo_lengths[order[i]] = 1;
      continue;
    }
    std::set<int32_t> children_bamboo_lengths;
    bool root = true;
    for (int32_t j = 0; j < tree[order[i]].size(); j++)
      if (bucket_id[tree[order[i]][j]] < bucket_id[order[i]]) {
        children_bamboo_lengths.insert(bamboo_lengths[tree[order[i]][j]]);
      } else {
        root = false;
      }
    if (!root) {
      if (children_bamboo_lengths.size() > 1) {
        std::cout << -1;
        return 0;
      }
      bamboo_lengths[order[i]] = (*children_bamboo_lengths.begin()) + 1;
    } else {
      if (children_bamboo_lengths.size() == 1) {
        bamboo_lengths[order[i]] = (*children_bamboo_lengths.begin()) + 1;
        std::cout << shorten(2 * bamboo_lengths[order[i]] - 2);
        return 0;
      } else if (children_bamboo_lengths.size() > 2) {
        std::cout << -1;
        exit(0);
      } else {
        auto it = children_bamboo_lengths.begin();
        bamboo_lengths[order[i]] = *it;
        it++;
        bamboo_lengths[order[i]] += *it;
        std::cout << shorten(bamboo_lengths[order[i]]) << "\n";
        return 0;
      }
    }
  }
  std::cout << 1;
  return 0;
}
