#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const int n_ = 2e5 + 5;
int n, st, nst, ok = 1, ans = 1e7;
vector<int> adj[n_];
set<int> ss;
int DFS(int u = st, int p = -1) {
  int ret = 0, done = 1;
  set<int> s;
  for (int i : adj[u]) {
    if (i != p) s.insert(DFS(i, u));
  }
  if (s.size() > (1 + (st == u))) {
    ok = 0;
    nst = u;
  }
  if (st == u) ss = s;
  return (s.size() ? (*s.rbegin()) : 0) + 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() > 2) {
      st = i;
      break;
    }
  }
  if (st) DFS();
  int rep = 10;
  while (!ok && rep--) {
    ok = 1;
    st = nst;
    DFS();
  }
  if (!ok)
    puts("-1");
  else {
    int x;
    if (st)
      x = (*ss.begin()) + (*ss.rbegin()) + 1;
    else
      x = n;
    while ((x & 1) && x > 1) {
      x = (x + 1) / 2;
    }
    printf("%d", x - 1);
  }
  return 0;
}
