#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 2e5 + 9;
int n;
bool no;
vector<vector<int> > adjL(N);
vector<int> parent(N, -1);
pair<int, int> dfs(int u, int par, int dep) {
  parent[u] = par;
  pair<int, int> ret = {u, dep};
  for (auto v : adjL[u]) {
    if (v == par) continue;
    pair<int, int> x = dfs(v, u, dep + 1);
    if (x.second > ret.second) ret = x;
  }
  return ret;
}
vector<int> TreeDiameter() {
  int node = dfs(1, -1, 0).first;
  parent = vector<int>(N, -1);
  node = dfs(node, -1, 0).first;
  vector<int> ret;
  while (node != -1) {
    ret.push_back(node);
    node = parent[node];
  }
  return ret;
}
int solve(int u, int par) {
  set<int> st;
  int hold = par;
  for (auto v : adjL[u]) {
    if (v == par) continue;
    hold = v;
    st.insert(solve(v, u));
  }
  if ((int)(st.size()) == 1) {
    adjL[u] = vector<int>(1, hold);
    return *st.begin() + 1;
  } else if (st.empty())
    return 1;
  if (par != -1)
    no = 1;
  else if ((int)(st.size()) > 2)
    no = 1;
  if (par == -1) {
    int ans = 1;
    for (auto it : st) ans += it;
    return ans;
  }
  return 0;
}
int main() {
  fast();
  file();
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adjL[u].push_back(v);
    adjL[v].push_back(u);
  }
  vector<int> a = TreeDiameter();
  int root = a[(int)(a.size()) / 2];
  int ans = solve(root, -1);
  if (no) return cout << -1 << "\n", 0;
  while (ans & 1) ans = ans / 2 + 1;
  cout << ans - 1 << "\n";
  return 0;
}
