#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<int> G[N];
int root;
int dfs(int cur, int fa) {
  set<int> s;
  for (auto v : G[cur])
    if (v != fa) {
      int tmp = dfs(v, cur);
      if (tmp == -1) return -1;
      s.insert(tmp + 1);
    }
  if (s.size() == 0)
    return 0;
  else if (s.size() == 1)
    return *s.begin();
  else if (s.size() == 2 && fa == 0)
    return *s.begin() + *s.rbegin();
  root = cur;
  return -1;
}
int main() {
  int n, u, v;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  int ans = dfs(1, 0);
  if (ans == -1 && root) ans = dfs(root, 0);
  while (ans % 2 == 0) {
    ans /= 2;
  }
  return 0 * printf("%d\n", ans);
}
