#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> tree[200200];
int dep[200200], newv;
int dfs(int c, int l, int d) {
  set<int> deps;
  for (int i : tree[c]) {
    if (i == l) continue;
    int res = dfs(i, c, d + 1);
    if (res == -1) return -1;
    deps.insert(res + 1);
  }
  if (deps.size() == 0) return 0;
  if (deps.size() == 1) return *deps.begin();
  if (deps.size() == 2 && l == -1) return *deps.begin() + *deps.rbegin();
  newv = c;
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int n1, n2;
    scanf(" %d%d", &n1, &n2);
    n1--;
    n2--;
    tree[n1].push_back(n2);
    tree[n2].push_back(n1);
  }
  int ans = dfs(0, -1, 0);
  if (ans == -1) ans = dfs(newv, -1, 0);
  if (ans == -1) {
    printf("-1\n");
    return 0;
  }
  while (ans % 2 == 0) ans /= 2;
  printf("%d\n", ans);
}
