10
4 2
7 4
2 6
2 5
4 8
10 3
2 9
9 1
5 10
 10
5 10
7 8
8 3
2 6
3 2
9 7
4 5
10 1
6 4
 4
4 1
4 3
4 2
 3
3 1
1 2
 9
1 2
1 3
1 4
1 5
1 6
6 7
6 8
8 9
 5
1 5
2 3
2 4
1 2
 8
6 1
4 7
4 8
8 5
7 6
4 3
4 2
 7
5 6
5 7
5 1
7 4
6 3
3 2
 3
1 3
3 2
 2
1 2
 5
5 4
4 3
3 1
5 2
 6
1 6
3 1
6 4
5 3
2 5
 11
8 9
2 7
1 11
3 2
9 1
8 5
8 6
5 4
4 10
8 3
 11
11 9
6 7
7 1
8 11
5 6
3 5
9 3
10 8
2 4
4 10
 12
12 6
6 7
8 11
4 8
10 4
12 3
2 10
6 2
12 9
4 1
9 5

-1
 9
 1
 1
 3
 3
 -1
 -1
 1
 1
 1
 5
 1
 5
 -1

#include <bits/stdc++.h>
using namespace std;
long long readi() {
  long long input = 0;
  char c = ' ';
  while (c < '-') {
    c = getchar();
  }
  bool negative = false;
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  while (c >= '0') {
    input = 10 * input + (c - '0');
    c = getchar();
  }
  if (negative) {
    input = -input;
  }
  return input;
}
void printi(long long output) {
  if (output == 0) {
    putchar('0');
    return;
  }
  if (output < 0) {
    putchar('-');
    output = -output;
  }
  int aout[20];
  int ilen = 0;
  while (output) {
    aout[ilen] = ((output % 10));
    output /= 10;
    ilen++;
  }
  for (int i = ilen - 1; i >= 0; i--) {
    putchar(aout[i] + '0');
  }
  return;
}
string reads() {
  string input = "";
  char c = ' ';
  while (c <= ' ') {
    c = getchar();
  }
  while (c > ' ') {
    input += c;
    c = getchar();
  }
  return input;
}
int sgn(long long x) {
  if (x < 0) {
    return -1;
  }
  if (x > 0) {
    return 1;
  }
  return 0;
}
long long randomize(long long x) {
  return (((1ll << 31) * rand()) + rand()) % x;
}
void yes() {
  cout << "Yes\n";
  exit(0);
}
void no() {
  cout << "No\n";
  exit(0);
}
void minus1() {
  cout << "-1\n";
  exit(0);
}
const long double PI = 4.0 * atan(1.0);
const long double EPS = 0.000000000000001;
long long normalize(long long x) {
  return (((x % 1000000007) + 1000000007) % 1000000007);
}
int N;
vector<int> edge[200010];
int parent[200010];
int head = 0;
int ans;
void dfs_par(int u) {
  for (int v : edge[u]) {
    if (v == parent[u]) {
      continue;
    }
    parent[v] = u;
    dfs_par(v);
  }
  return;
}
int solve(int u) {
  set<int> res;
  if (edge[u].size() == 1 && edge[u][0] == parent[u]) {
    return 0;
  }
  for (int v : edge[u]) {
    if (v == parent[u]) {
      continue;
    }
    res.insert(solve(v) + 1);
  }
  if (res.find(0) != res.end()) {
    return -1;
  }
  if (res.size() > 2) {
    minus1();
  }
  if (res.size() == 2) {
    if (u == head) {
      int val = *res.begin() + *res.rbegin();
      while (val % 2 == 0) {
        val /= 2;
      }
      return val;
    }
    head = u;
    return -1;
  }
  return *res.begin();
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  if (fopen("cf765e.in", "r")) {
    freopen("cf765e.in", "r", stdin);
    freopen("cf765e.out", "w", stdout);
  }
  cin >> N;
  for (int i = 1; i < N; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  for (int i = 0; i < N; i++) {
    parent[i] = N;
  }
  dfs_par(0);
  int val = solve(0);
  if (val != -1) {
    while (val % 2 == 0) {
      val /= 2;
    }
    cout << val << '\n';
    return 0;
  }
  for (int i = 0; i < N; i++) {
    parent[i] = N;
  }
  dfs_par(head);
  val = solve(head);
  while (val % 2 == 0) {
    val /= 2;
  }
  cout << val << '\n';
}
