#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200010];
int n, deg[200010];
int find_center() {
  queue<int> fila;
  for (int i = 0; i < n; i++)
    if (deg[i] == 1) {
      fila.push(i);
    }
  int ans = 0;
  while (((int)(fila).size())) {
    int v = fila.front();
    fila.pop();
    for (auto &it : adj[v]) {
      deg[it]--;
      if (deg[it] == 1) fila.push(it);
    }
    ans = v;
  }
  return ans;
}
int solve(int v, int fat = -1) {
  set<int> tm;
  for (auto &it : adj[v]) {
    if (it != fat) {
      int tam = solve(it, v);
      tm.insert(tam);
    }
  }
  if (((int)(tm).size()) == 1) {
    return (*tm.begin()) + 1;
  } else if (((int)(tm).size()) == 2 && fat == -1) {
    return *tm.begin() + (*next(tm.begin())) + 1;
  } else if (((int)(tm).size()) == 0)
    return 1;
  cout << -1 << '\n';
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  int root = find_center();
  int tam = solve(root) - 1;
  while (tam % 2 == 0) tam /= 2;
  cout << tam << '\n';
}
