#include <bits/stdc++.h>
using namespace std;
set<int> g[1000005], d[1000005];
queue<int> q;
int vis[1000005];
int solve(int n) {
  int res = -1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (vis[u]) continue;
    if (g[u].size() == 0) {
      res = *d[u].begin() + *d[u].rbegin();
      break;
    } else if (g[u].size() == 1) {
      if (d[u].size() == 1) {
        vis[u] = 1;
        int v = *g[u].begin();
        g[u].erase(v);
        g[v].erase(u);
        q.push(v);
        d[v].insert(*d[u].begin() + 1);
        if (d[v].size() > 2) return -1;
      }
    }
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].insert(v);
    g[v].insert(u);
  }
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) {
      q.push(i);
      d[i].insert(0);
    }
  }
  int ans = solve(n);
  while (ans % 2 == 0) ans /= 2;
  printf("%d\n", ans);
}
