#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, tot, fr[maxn], lis[maxn];
int ecnt, pt[maxn << 1], nt[maxn << 1], hd[maxn];
void ins(int u, int v) {
  pt[++ecnt] = v;
  nt[ecnt] = hd[u];
  hd[u] = ecnt;
}
int Mx, Id;
void dfs(int x, int f, int d) {
  int i;
  fr[x] = f;
  if (d > Mx) Mx = d, Id = x;
  for (i = hd[x]; i; i = nt[i])
    if (pt[i] != f) dfs(pt[i], x, d + 1);
}
int tar;
void dfs2(int x, int f, int d) {
  int i, islef = 1;
  for (i = hd[x]; i; i = nt[i])
    if (pt[i] != f) dfs2(pt[i], x, d + 1), islef = 0;
  if (islef) {
    if (d == tar) return;
    if (tar == -1)
      tar = d;
    else
      puts("-1"), exit(0);
  }
}
int main() {
  int i, j, x, u, v, mid = 0;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    ins(u, v);
    ins(v, u);
  }
  Mx = -1;
  dfs(1, 0, 0);
  Mx = -1;
  dfs(Id, 0, 0);
  for (i = Id; i; i = fr[i]) lis[++tot] = i;
  if (tot & 1) mid = tot / 2 + 1;
  for (j = 2; j < tot; j++) {
    if (j == mid) continue;
    x = lis[j];
    tar = min(j - 1, tot - j);
    for (i = hd[x]; i; i = nt[i])
      if (pt[i] != lis[j - 1] && pt[i] != lis[j + 1]) dfs2(pt[i], x, 1);
  }
  int ans = 0;
  if (mid) {
    x = lis[mid];
    int tmp = -1;
    for (i = hd[x]; i; i = nt[i])
      if (pt[i] != lis[mid - 1] && pt[i] != lis[mid + 1]) {
        tar = -1;
        dfs2(pt[i], x, 1);
        if (tar == mid - 1 || tar == tmp) continue;
        if (tmp == -1)
          tmp = tar;
        else
          return puts("-1"), 0;
      }
    if (tmp != -1)
      ans = tmp + mid;
    else
      ans = tot;
  } else
    ans = tot;
  while ((ans & 1) && (ans > 1)) ans = ans / 2 + 1;
  printf("%d\n", ans - 1);
  return 0;
}
