#include <bits/stdc++.h>
using namespace std;
struct arr {
  int aa, bb;
} na[400010];
int n, nn, s, x, y, root, head[200010];
void add(int x, int y) {
  nn = nn + 1;
  na[nn].aa = y;
  na[nn].bb = head[x];
  head[x] = nn;
}
int dfs(int u, int k) {
  set<int> T;
  for (int i = head[u]; i; i = na[i].bb) {
    int j = na[i].aa;
    if (j == k) continue;
    int sum = dfs(j, u);
    if (sum == -1) return -1;
    if (sum != -1) T.insert(sum + 1);
  }
  if (T.size() == 0) return 0;
  if (T.size() == 1) return *T.begin();
  if ((T.size() == 2) && (k == 0)) return *T.begin() + *T.rbegin();
  root = u;
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  root = 1;
  s = dfs(1, 0);
  if ((s == -1) && (root != 1)) s = dfs(root, 0);
  while (s % 2 == 0) s = s / 2;
  printf("%d\n", s);
  return 0;
}
