#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int tot = 1;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') c = getchar(), tot = -1;
  int sum = 0;
  while (c >= '0' && c <= '9') sum = sum * 10 + c - '0', c = getchar();
  return sum * tot;
}
const int N = 4 * 100005;
int root, pos, nxt[N], head[N], v[N];
void add(int u, int y) {
  nxt[++pos] = head[u];
  v[pos] = y;
  head[u] = pos;
}
int dfs(int u, int fa) {
  set<int> s;
  for (int i = head[u]; i; i = nxt[i]) {
    int j = v[i];
    if (j == fa) continue;
    int tmp = dfs(j, u);
    if (tmp == -1) return -1;
    s.insert(tmp + 1);
  }
  if (s.size() == 0) return 0;
  if (s.size() == 1) return *s.begin();
  if (s.size() == 2 && u == root) return *s.begin() + *s.rbegin();
  root = u;
  return -1;
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  int ans = dfs(1, 0);
  if (ans == -1) ans = dfs(root, 0);
  while (!(ans & 1)) ans >>= 1;
  cout << ans << endl;
}
