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 T>
inline void rd(T &x) {
  x = 0;
  char c;
  int f = 1;
  while (c = getchar(), c < 48)
    if (c == '-') f = -1;
  do x = x * 10 + (c & 15);
  while (c = getchar(), c > 47);
  x *= f;
}
template <class T>
void prin(T x) {
  if (!x) return;
  prin(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
void pf(T x) {
  if (x < 0)
    putchar('-'), x = -x;
  else if (!x)
    putchar('0');
  prin(x);
}
template <class T>
void ptn(T x) {
  pf(x);
  putchar('\n');
}
template <class T>
void ptk(T x) {
  pf(x);
  putchar(' ');
}
template <class T>
void Min(T &A, T B) {
  if (A > B) A = B;
}
template <class T>
void Max(T &A, T B) {
  if (A < B) A = B;
}
const int N = (int)2e5;
pair<int, int> G[N << 1];
int head[N], tot, n;
int par[N], dep[N], id, mx;
void dfs(int x) {
  if (dep[x] > mx) {
    mx = dep[x];
    id = x;
  }
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x]) continue;
    par[y] = x;
    dep[y] = dep[x] + 1;
    dfs(y);
  }
}
int que[N], fir[N], sec[N];
bool Lcan[N], Rcan[N];
bool mark[N];
struct ss {
  int fir, sec, thr;
};
ss getans(int x) {
  set<int> a;
  a.clear();
  for (int i = head[x]; i; i = G[i].second) {
    int y = G[i].first;
    if (y == par[x] || mark[y]) continue;
    par[y] = x;
    ss tmp = getans(y);
    if (tmp.thr == 0) return (ss){0, 0, 0};
    if (tmp.sec) return (ss){0, 0, 0};
    a.insert(tmp.fir);
  }
  if (a.size() > 2) return (ss){0, 0, 0};
  if (!a.size()) return (ss){1, 0, 1};
  if (a.size() == 1) return (ss){(*a.begin()) + 1, 0, 1};
  ss b;
  b.fir = (*a.begin()) + 1;
  a.erase(b.fir);
  b.sec = (*a.begin()) + 1;
  b.thr = 1;
  return b;
}
int main() {
  rd(n);
  for (int x, y, i = 1; i < n; ++i) {
    rd(x);
    rd(y);
    G[++tot] = pair<int, int>(y, head[x]);
    head[x] = tot++;
    G[++tot] = pair<int, int>(x, head[y]);
    head[y] = tot++;
  }
  mx = -1, par[id = 1] = 0;
  dfs(1);
  mx = -1;
  dep[id] = 0;
  par[id] = 0;
  dfs(id);
  int cnt = 0;
  while (id) {
    que[++cnt] = id;
    mark[id] = 1;
    id = par[id];
  }
  Lcan[1] = Lcan[2] = true;
  Rcan[cnt] = Rcan[cnt - 1] = true;
  for (int i = (2), _t = (cnt); i < _t; ++i) {
    par[que[i]] = 0;
    ss tmp = getans(que[i]);
    if (tmp.thr == 0) {
      puts("-1");
      return 0;
    }
    tmp.fir--;
    if (Lcan[i] && tmp.fir != i - 1) {
      fir[i] = tmp.fir;
    }
    if (Lcan[i] && tmp.sec) {
      tmp.sec--;
      if (tmp.sec != i - 1) {
        if (fir[i])
          sec[i] = tmp.sec;
        else
          fir[i] = tmp.sec;
      }
    }
    if (fir[i] || sec[i] || !Lcan[i])
      Lcan[i + 1] = false;
    else
      Lcan[i + 1] = true;
  }
  for (int i = (cnt)-1, _s = (2); i >= _s; --i) {
    if (Rcan[i]) {
      if (fir[i]) {
        if (fir[i] == cnt - i) fir[i] = 0;
      }
      if (sec[i]) {
        if (sec[i] == cnt - i) sec[i] = 0;
      }
    }
    if (fir[i] || sec[i] || !Rcan[i])
      Rcan[i - 1] = false;
    else
      Rcan[i - 1] = true;
  }
  int c = 0;
  for (int i = (2), _t = (cnt); i < _t; ++i)
    if (fir[i] || sec[i]) c++;
  if (c > 1) {
    puts("-1");
    return 0;
  }
  for (int i = (2), _t = (cnt); i < _t; ++i)
    if (fir[i] || sec[i]) {
      if (fir[i] && sec[i]) {
        puts("-1");
        return 0;
      }
      if (mx & 1) {
        puts("-1");
        return 0;
      }
      int lg = fir[i] | sec[i];
      mx >>= 1;
      mx += lg;
    }
  while (!(mx & 1)) mx >>= 1;
  ptn(mx);
  return 0;
}
