#include <bits/stdc++.h>
using namespace std;
vector<int> V[200005];
int rt1, rt2;
int dfs(int u, int f, int rt) {
  set<int> S;
  S.clear();
  for (int i = 0; i < V[u].size(); i++) {
    int v = V[u][i];
    if (v == f) continue;
    int tmp = dfs(v, u, rt);
    if (tmp == -1) return -1;
    S.insert(tmp + 1);
  }
  int sz = S.size();
  if (sz == 0)
    return 0;
  else if (sz == 1)
    return *S.begin();
  else if (sz == 2 && u == rt)
    return *S.begin() + *S.rbegin();
  else {
    rt2 = u;
    return -1;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    V[x].push_back(y);
    V[y].push_back(x);
  }
  rt1 = 1;
  int ans = dfs(rt1, 0, rt1);
  if (ans == -1) ans = dfs(rt2, 0, rt2);
  if (ans == -1)
    printf("-1\n");
  else {
    while (!(ans & 1)) ans >>= 1;
    printf("%d\n", ans);
  }
}
