#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> e[N];
set<int> l[N];
int n;
void exitno() {
  printf("-1\n");
  exit(0);
}
int exitans(int x) {
  while (x % 2 == 0) x /= 2;
  printf("%d\n", x);
  exit(0);
}
void _dfs(int p, int fa) {
  if (fa && e[p].size() == 1) l[p].insert(0);
  for (int i = 0; i < e[p].size(); i++) {
    int x = e[p][i];
    if (x == fa) continue;
    _dfs(x, p);
    for (auto j : l[x]) l[p].insert(j + 1);
  }
  if (l[p].size() >= 3) exitno();
}
void work(int p) {
  for (int i = 1; i <= n; i++) l[i].clear();
  _dfs(p, 0);
  int x = 0;
  for (auto i : l[p]) x += i;
  exitans(x);
}
void dfs(int p = 1, int fa = 0) {
  if (fa && e[p].size() == 1) l[p].insert(0);
  for (int i = 0; i < e[p].size(); i++) {
    int x = e[p][i];
    if (x == fa) continue;
    dfs(x, p);
    for (auto j : l[x]) l[p].insert(j + 1);
  }
  if (l[p].size() >= 3) exitno();
  if (l[p].size() == 2) work(p);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs();
  exitans(*l[1].begin());
  return 0;
}
