#include <bits/stdc++.h>
using namespace std;
int n, top, a, b, nxtroot, head[200001];
struct node {
  int too, next;
} edge[200001 << 1];
inline void add(int a, int b) {
  edge[++top].too = b;
  edge[top].next = head[a];
  head[a] = top;
}
set<int> s[200001];
inline int dfs(int x, int fa) {
  s[x].clear();
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].too != fa) {
      int y = edge[i].too, t = dfs(y, x);
      if (t == -1) return -1;
      s[x].insert(t + 1);
    }
  if (s[x].size() == 0) return 0;
  if (s[x].size() == 1) return *s[x].begin();
  if (s[x].size() == 2 && x == fa) return *s[x].rbegin() + *s[x].begin();
  nxtroot = x;
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
  }
  int res = dfs(1, 1);
  if (res == -1 && nxtroot) res = dfs(nxtroot, nxtroot);
  if (res == -1) {
    cout << -1;
    return 0;
  }
  while ((res & 1) == 0) res >>= 1;
  cout << res;
  return 0;
}
