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>
using namespace std;
template <class Q>
Q _sqr(Q x) {
  return x * x;
}
template <class Q>
void gi(Q &x) {
  char ch = getchar();
  x = 0;
  int s = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') s = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
  if (s == -1) x = -x;
}
template <class Q>
void pi(Q x) {
  if (x < 0) {
    putchar('-');
    pi(-x);
  } else {
    if (x > 9) pi(x / 10);
    putchar(x % 10 + 48);
  }
}
const int sz = 400200;
const int huge = 1000000000;
const long long int hugell = 1ll << 61;
const double hugelf = 1e50;
const double eps = 1e-10;
const int ljz = 1000000007;
void MOD(int &x) {
  if (x >= ljz) x -= ljz;
  if (x < 0) x += ljz;
}
int Tm(int a, int b) {
  long long int x = a, y = b;
  return (x * y) % ljz;
}
int fpm(int x, int y) {
  int p = 1, s = x;
  for (; y; y >>= 1) {
    if (y & 1) p = Tm(p, s);
    s = Tm(s, s);
  }
  return p;
}
int Tm(int a, int b, int c) { return Tm(Tm(a, b), c); }
int Tm(int a, int b, int c, int d) { return Tm(Tm(a, b, c), d); }
int Tm(int a, int b, int c, int d, int e) { return Tm(Tm(a, b, c, d), e); }
int Tm(int a, int b, int c, int d, int e, int f) {
  return Tm(Tm(a, b, c, d, e), f);
}
int node[sz], nxt[sz], to[sz], e;
void ins(int x, int y) {
  e++;
  nxt[e] = node[x];
  node[x] = e;
  to[e] = y;
}
int n, a, b;
int deg[sz];
int q[sz], dep[sz], par[sz], ooo[sz];
void bfs(int x) {
  int i, j, k, l, r;
  for (i = 1; i <= n; i++) dep[i] = par[i] = 0;
  q[l = r = 1] = x;
  while (l <= r)
    for (j = node[k = q[l++]]; j; j = nxt[j])
      if (to[j] != par[k]) {
        par[q[++r] = to[j]] = k;
        dep[to[j]] = dep[k] + 1;
        if (k == x)
          ooo[to[j]] = to[j];
        else
          ooo[to[j]] = ooo[k];
      }
}
int d1, d2, indiam[sz], dd[sz], _par[sz];
int get() {
  int i, j;
  bfs(1);
  for (i = j = 1; i <= n; i++)
    if (dep[i] > dep[j]) j = i;
  bfs(j);
  d1 = j;
  for (i = 1, d2 = 0; i <= n; i++)
    if (dep[i] > dep[d2]) d2 = i;
  return dep[d2];
}
int bel[sz];
void _try(int d) {
  int i, x, a1 = 0, a2 = 0;
  for (x = d2, i = d; i; i--) x = _par[x];
  for (i = 1; i <= n; i++) bel[i] = 0;
  bfs(x);
  for (i = 1; i <= n; i++)
    if (deg[i] == 1) {
      if (bel[ooo[i]] == 0)
        bel[ooo[i]] = dep[i];
      else if (bel[ooo[i]] != dep[i])
        return;
    }
  for (i = 1; i <= n; i++)
    if (bel[i] != 0) {
      if (a1 == 0)
        a1 = bel[i];
      else if (bel[i] != a1) {
        if (a2 == 0)
          a2 = bel[i];
        else if (bel[i] != a2)
          return;
      }
    }
  if (a2 == 0) a2 = a1;
  printf("%d", a1 + a2);
  exit(0);
}
void fail() {
  printf("-1");
  exit(0);
}
int main() {
  int l = 0, i;
  gi(n);
  if (n == 2) return printf("1"), 0;
  for (i = 1; i < n; i++) {
    gi(a);
    gi(b);
    ins(a, b);
    ins(b, a);
    deg[a]++;
    deg[b]++;
  }
  int ans = get();
  for (i = 1; i <= n; i++) _par[i] = par[i];
  _try(ans >> 1);
  _try((ans >> 1) - 1);
  _try((ans >> 1) + 1);
  printf("-1");
  return 0;
}
