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;
bool is_path[222222];
int path_length[222222];
vector<int> children[222222];
void update_pathity(int v) {
  if (children[v].size() == 0) {
    is_path[v] = true;
    path_length[v] = 0;
  } else if (children[v].size() == 1 && is_path[children[v][0]]) {
    is_path[v] = true;
    path_length[v] = path_length[children[v][0]] + 1;
  } else {
    is_path[v] = false;
  }
}
void rotate(int old_root, int new_root) {
  for (auto it = children[old_root].begin(); it != children[old_root].end();
       ++it) {
    if (*it == new_root) {
      children[old_root].erase(it);
      break;
    }
  }
  update_pathity(old_root);
  children[new_root].push_back(old_root);
  update_pathity(new_root);
}
void reduce(int v) {
  vector<int> new_children;
  set<int> path_lengths;
  for (int k : children[v]) {
    if (!is_path[k]) {
      new_children.push_back(k);
    } else if (path_lengths.find(path_length[k]) == path_lengths.end()) {
      path_lengths.insert(path_length[k]);
      new_children.push_back(k);
    }
  }
  children[v] = new_children;
}
void dfs2(int v) {
  for (int k : children[v]) dfs2(k);
  reduce(v);
  update_pathity(v);
}
vector<int> adj[222222];
void dfs(int v, int p = -1) {
  for (auto k : adj[v])
    if (k != p) {
      children[v].push_back(k);
      dfs(k, v);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  int N;
  scanf("%d", &N);
  for (int i = 0; i < (N - 1); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0);
  dfs2(0);
  int r = 0;
  while (true) {
    if (children[r].size() > 2) {
      printf("-1\n");
      return 0;
    }
    int non_path_child = -1;
    int path_sum = 0;
    for (auto k : children[r]) {
      if (is_path[k])
        path_sum += path_length[k] + 1;
      else if (non_path_child != -1) {
        printf("-1\n");
        return 0;
      } else {
        non_path_child = k;
      }
    }
    if (non_path_child == -1) {
      while (path_sum % 2 == 0) path_sum /= 2;
      printf("%d\n", path_sum);
      return 0;
    }
    rotate(r, non_path_child);
    r = non_path_child;
    reduce(r);
  }
}
