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 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;
}
