#include <bits/stdc++.h>
using namespace std;
const long long Max = 2e5 + 10;
long long n;
vector<long long> adj[Max];
long long par[Max];
pair<long long, long long> bfs(long long start) {
  queue<long long> q;
  q.push(start);
  vector<long long> dist(n + 1, n + 1);
  dist[start] = 0;
  par[start] = -1;
  while (!q.empty()) {
    const long long node = q.front();
    q.pop();
    for (long long to : adj[node]) {
      if (dist[to] > 1 + dist[node]) {
        dist[to] = 1 + dist[node];
        par[to] = node;
        q.push(to);
      }
    }
  }
  long long mx = -1;
  long long farNode;
  for (long long i = 1; i <= n; ++i) {
    if (dist[i] < n + 1 && dist[i] > mx) {
      mx = dist[i];
      farNode = i;
    }
  }
  return {farNode, mx};
}
vector<long long> rootDepths;
void dfs(long long node, long long par, long long depth) {
  if (adj[node].size() == 1) {
    rootDepths.push_back(depth);
  }
  for (long long to : adj[node]) {
    if (to == par) continue;
    dfs(to, node, depth + 1);
  }
}
long long getAns(long long size) {
  while (size > 1 && size % 2 == 1) {
    size = (size + 1) / 2;
  }
  return size;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  pair<long long, long long> far = bfs(1);
  far = bfs(far.first);
  vector<long long> diameter;
  long long curr = far.first;
  vector<bool> onDiam(n + 1, false);
  diameter.push_back(curr);
  onDiam[curr] = true;
  while (par[curr] != -1) {
    curr = par[curr];
    diameter.push_back(curr);
    onDiam[curr] = true;
  }
  vector<long long> candidates;
  for (long long i = max(0LL, (long long)diameter.size() / 2 - 1);
       i < diameter.size() && i <= diameter.size() / 2 + 1; ++i) {
    candidates.push_back(diameter[i]);
  }
  long long res = -1;
  for (long long root : candidates) {
    bool good = true;
    set<long long> currDepths;
    for (long long to : adj[root]) {
      rootDepths.clear();
      dfs(to, root, 1);
      sort(rootDepths.begin(), rootDepths.end());
      rootDepths.erase(unique(rootDepths.begin(), rootDepths.end()),
                       rootDepths.end());
      if (rootDepths.size() != 1) {
        good = false;
      }
      currDepths.insert(rootDepths[0]);
    }
    if (good && (currDepths.size() == 1 || currDepths.size() == 2)) {
      long long len = 1;
      for (long long x : currDepths) len += x;
      if (res == -1) {
        res = getAns(len);
      } else
        res = min(res, getAns(len));
    }
  }
  if (res == -1)
    cout << res << '\n';
  else
    cout << res - 1 << '\n';
  return 0;
}
