#include <bits/stdc++.h>
using namespace std;
const int MAX = 200200;
int head[MAX], nxt[MAX * 2], to[MAX * 2], dpthMx[MAX], dpthMn[MAX], Ecnt, n;
int ch[MAX], sz, from[MAX];
void dfs(int cur, int par) {
  for (int i = head[cur]; ~i; i = nxt[i])
    if (to[i] != par) {
      dfs(to[i], cur);
      dpthMn[cur] = min(dpthMn[cur], dpthMn[to[i]] + 1);
      dpthMx[cur] = max(dpthMx[cur], dpthMx[to[i]] + 1);
    }
  if (dpthMn[cur] == MAX) dpthMn[cur] = 0;
}
pair<int, int> dfs0(int cur, int par, int d) {
  from[cur] = par;
  pair<int, int> ret(d, cur);
  for (int i = head[cur]; ~i; i = nxt[i])
    if (to[i] != par) ret = max(ret, dfs0(to[i], cur, d + 1));
  return ret;
}
void addEdge(int u, int v) {
  nxt[Ecnt] = head[u];
  head[u] = Ecnt;
  to[Ecnt++] = v;
}
int main() {
  scanf("%d", &n);
  memset(head, -1, (n + 1) * sizeof head[0]);
  fill(dpthMn, dpthMn + n + 1, MAX);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  pair<int, int> diam = dfs0(dfs0(1, 0, 0).second, 0, 0);
  while (diam.first > 0) diam.first -= 2, diam.second = from[diam.second];
  dfs(diam.second, 0);
  for (int i = head[diam.second]; ~i; i = nxt[i]) {
    if (dpthMx[to[i]] != dpthMn[to[i]]) return puts("-1"), 0;
    ch[sz++] = dpthMx[to[i]] + 1;
  }
  sort(ch, ch + sz);
  sz = unique(ch, ch + sz) - ch;
  if (sz > 2) return puts("-1"), 0;
  ch[sz] = 0;
  int ans = ch[0] + ch[1];
  while (!(ans & 1)) ans >>= 1;
  printf("%d\n", ans);
  return 0;
}
