10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
 10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
 4
4 1
4 3
4 2
 3
3 1
1 2
 9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
 5
1 5
2 3
2 4
1 2
 8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
 7
5 6
5 7
5 1
7 4
6 3
3 2
 3
1 3
3 2
 2
1 2
 5
5 4
4 3
3 1
5 2
 6
1 6
3 1
6 4
5 3
2 5
 11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
 11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
 12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5

-1
 9
 1
 1
 3
 3
 -1
 -1
 1
 1
 1
 5
 1
 5
 -1

#include <bits/stdc++.h>
unsigned *G[222222], Ga[222222], Gi[222222];
void add(unsigned i, unsigned j) {
  if (Ga[i] == Gi[i]) {
    if (!Ga[i])
      G[i] = (unsigned *)calloc(Ga[i] = 1, sizeof(unsigned));
    else
      G[i] = (unsigned *)realloc(G[i], (Ga[i] <<= 1) * sizeof(unsigned));
  }
  G[i][Gi[i]++] = j;
  return;
}
unsigned P[222222], D[222222], IL[222222], mi, ma;
void F(unsigned n, unsigned p, unsigned d) {
  if (!d) {
    mi = -1;
    ma = 0;
  }
  unsigned i, j;
  P[n] = p;
  D[n] = d;
  if (IL[n]) {
    if (mi > d) mi = d;
    if (ma < d) ma = d;
  }
  for (i = Gi[n]; i--;)
    if ((j = G[n][i]) != p) F(j, n, d + 1);
  return;
}
unsigned L[222222], Li, Q[9], Qi;
int main() {
  unsigned n, i, j, k, x;
  scanf("%u", &n);
  for (k = n; --k;) {
    scanf("%u%u", &i, &j);
    add(i, j);
    add(j, i);
  }
  for (i = 0; ++i <= n;)
    if (Gi[i] == 1) IL[L[Li++] = i] = 1;
  F(L[0], 0, 0);
  for (i = j = k = 0; ++i <= n;)
    if (D[i] > k) k = D[j = i];
  F(j, 0, 0);
  for (i = j = k = 0; ++i <= n;)
    if (D[i] > k) k = D[j = i];
  for (i = k >> 1; i--;) j = P[j];
  if (k & 1) {
    F(i = P[j], j, 0);
    if (mi != ma) goto NO;
    F(j, i, 0);
    if (mi != ma) goto NO;
  } else {
    for (i = Gi[j]; i--;) {
      F(G[j][i], j, 0);
      if (mi != ma) goto NO;
      for (x = -1; ++x < Qi;)
        if (Q[x] == mi) goto tebak;
      Q[Qi++] = mi;
      if (Qi > 2) goto NO;
    tebak:;
    }
    for (k = 0, x = -1; ++x < Qi;) k += Q[x] + 1;
  }
  while (!(k & 1)) k >>= 1;
  printf("%u\n", k);
  return 0;
NO:;
  printf("-1\n");
  return 0;
}
