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;
vector<int> Graph[200010];
int Far_dist[200010], Children[200010];
int Max = 0, vertex = -1, left_child = 0, right_child = 0;
int dfs(int root, int Parent) {
  int i, height = -1, Temp;
  if (Graph[root].size() == 1 && Graph[root][0] == Parent) return 0;
  for (i = 0; i < Graph[root].size(); i++) {
    if (Graph[root][i] != Parent) {
      Temp = dfs(Graph[root][i], root);
      Far_dist[Graph[root][i]] = Temp;
      if (Temp > height) height = Temp;
    }
  }
  return height + 1;
}
void dfs_Children(int root, int Parent) {
  int i, Max1 = 0, Max2 = 0, u = -1, v = -1;
  if (!Graph[root].size()) {
    vertex = root;
    Children[root] = -1;
    return;
  }
  for (i = 0; i < Graph[root].size(); i++) {
    if (Graph[root][i] != Parent) {
      if (Far_dist[Graph[root][i]] >= Max1) {
        Max2 = Max1;
        v = u;
        Max1 = Far_dist[Graph[root][i]];
        u = Graph[root][i];
      } else if (Far_dist[Graph[root][i]] >= Max2 &&
                 Far_dist[Graph[root][i]] < Max1) {
        Max2 = Far_dist[Graph[root][i]];
        v = Graph[root][i];
      }
    }
  }
  Children[root] = u;
  if (v == -1) Max2 = -1;
  if (u == -1) Max1 = -1;
  if (Max1 + Max2 + 2 >= Max) {
    Max = Max1 + Max2 + 2;
    vertex = root;
    left_child = u;
    right_child = v;
  }
  for (i = 0; i < Graph[root].size(); i++)
    if (Graph[root][i] != Parent) dfs_Children(Graph[root][i], root);
}
pair<int, int> Diameter_Center(int root, int h1, bool Check) {
  pair<int, int> Center;
  if (Far_dist[root] == h1) {
    Center.first = root;
    if (Check)
      Center.second = Children[root];
    else
      Center.second = -1;
  } else
    Center = Diameter_Center(Children[root], h1, Check);
  return Center;
}
bool Check_Subtree(int root, int Parent) {
  int h1, i;
  bool Result;
  if (Graph[root].size() >= 2) {
    if (Graph[root][0] != Parent)
      h1 = Far_dist[Graph[root][0]];
    else
      h1 = Far_dist[Graph[root][1]];
  }
  for (i = 0; i < Graph[root].size(); i++) {
    if (Graph[root][i] != Parent)
      if (Far_dist[Graph[root][i]] != h1) return 0;
  }
  for (i = 0; i < Graph[root].size(); i++)
    if (Graph[root][i] != Parent)
      if (!Check_Subtree(Graph[root][i], root)) return 0;
  return 1;
}
pair<int, int> Check_Folding(int root) {
  int i, h1 = 0, h2 = -1;
  pair<int, int> Path_Length;
  Path_Length.first = Path_Length.second = 0;
  if (Graph[root].size() >= 2) {
    h1 = Far_dist[Graph[root][0]];
    for (i = 1; i < Graph[root].size(); i++) {
      if (Far_dist[Graph[root][i]] != h1) {
        h2 = Far_dist[Graph[root][i]];
        i++;
        break;
      }
    }
    if (h2 == -1) h2 = h1;
    for (; i < Graph[root].size(); i++) {
      if (Far_dist[Graph[root][i]] != h1 && Far_dist[Graph[root][i]] != h2)
        return Path_Length;
    }
  }
  if (Graph[root].size() == 1)
    Path_Length.first = h1 + 1;
  else
    Path_Length.first = h1 + h2 + 2;
  for (i = 0; i < Graph[root].size(); i++) {
    if (!Check_Subtree(Graph[root][i], root)) return Path_Length;
  }
  Path_Length.second = 1;
  return Path_Length;
}
int main() {
  int i, N, u, v;
  pair<int, int> Center, Path_Length;
  cin >> N;
  for (i = 1; i <= N - 1; i++) {
    cin >> u >> v;
    Graph[u].emplace_back(v);
    Graph[v].emplace_back(u);
  }
  Far_dist[1] = dfs(1, -1);
  dfs_Children(1, -1);
  if (Max % 2) {
    if (Far_dist[vertex] == (Max / 2) + 1) {
      Center = Diameter_Center(left_child, Max / 2, 0);
      Center.second = vertex;
    } else
      Center = Diameter_Center(left_child, (Max / 2) + 1, 1);
  } else {
    if (Far_dist[vertex] == Max / 2) {
      Center.first = vertex;
      Center.second = -1;
    } else
      Center = Diameter_Center(left_child, Max / 2, 0);
  }
  Far_dist[Center.first] = dfs(Center.first, -1);
  Path_Length = Check_Folding(Center.first);
  if (Path_Length.second) {
    if (!(Path_Length.first % 2)) {
      while (!(Path_Length.first % 2)) Path_Length.first /= 2;
    }
  } else {
    if (Path_Length.first % 2) {
      Far_dist[Center.second] = dfs(Center.second, -1);
      Path_Length = Check_Folding(Center.second);
      if (!Path_Length.second) Path_Length.first = -1;
    } else
      Path_Length.first = -1;
  }
  cout << Path_Length.first << endl;
  return 0;
}
