Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:

<image>

Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.

Input

The first line of input contains the number of vertices n (2 ≤ n ≤ 2·105).

Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.

Output

If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.

Examples

Input

6
1 2
2 3
2 4
4 5
1 6


Output

3


Input

7
1 2
1 3
3 4
1 5
5 6
6 7


Output

-1

Note

In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.

It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getnum(T& x) {
  short sign = 1;
  x = 0;
  char c;
  do c = getchar();
  while (c == ' ' || c == '\n');
  if (c == EOF) return false;
  if (c == '-')
    sign = -1;
  else
    x = c - '0';
  for (c = getchar(); '0' <= c && c <= '9';
       (x = x * 10 + c - '0', c = getchar()))
    ;
  x *= sign;
  return true;
}
template <class T>
inline bool _R(T& x) {
  return (bool)(cin >> x);
}
inline bool _R(int& x) { return getnum(x); }
inline bool _R(unsigned& x) { return getnum(x); }
inline bool _R(long long& x) { return getnum(x); }
inline bool _R(unsigned long long& x) { return getnum(x); }
inline bool _R(double& x) { return scanf("%lf", &x); }
inline bool _R(char& x) { return scanf("%c", &x); }
inline bool _R(char* x) { return scanf("%s", x); }
template <class T>
inline bool _W(const T& x) {
  cout << x;
  return 0;
}
inline bool _W(const int& x) {
  printf("%d", x);
  return 0;
}
inline bool _W(const long long& x) {
  printf("%lld", x);
  return 0;
}
inline bool _W(const unsigned long long& x) {
  printf("%llu", x);
  return 0;
}
inline bool _W(const double& x) {
  printf("%.16f", x);
  return 0;
}
inline bool _W(const char& x) {
  putchar(x);
  return 0;
}
inline bool _W(const char* x) {
  int i = 0;
  while (x[i]) putchar(x[i++]);
  return 0;
}
inline bool _W(const string& x) {
  int i = 0;
  while (x[i]) putchar(x[i++]);
  return 0;
}
template <class T, class U>
inline bool _W(const pair<T, U>& x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
  return 0;
}
template <class T>
inline bool _W(const vector<T>& x) {
  for (typename vector<T>::iterator i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
  return 0;
}
const int movex[] = {+0, +1, +0, -1, -1, +1, +1, -1};
const int movey[] = {-1, +0, +1, +0, -1, -1, +1, +1};
vector<int> adj[200010];
int root;
int dfs(int i, int par) {
  set<int> st;
  int ret;
  for (auto it : adj[i]) {
    if (it != par) {
      ret = dfs(it, i);
      if (ret == -1) return -1;
      st.insert(ret + 1);
      if (st.size() > 2) return -1;
    }
  }
  if (st.size() > 1 && par) {
    root = i;
    return -1;
  }
  int sum = 0;
  for (auto it : st) sum += it;
  return sum;
}
int main() {
  int n;
  (_R(n));
  for (int i = 0, a, b; i < n - 1; ++i) {
    (_R(a) & (_R(b)));
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans;
  ans = dfs(1, 0);
  if (root) {
    ans = dfs(root, 0);
  }
  while (ans % 2 == 0) ans /= 2;
  (_W(ans) & (_W('\n')));
  return 0;
}
