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;
const pair<int, int> DD[] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                             {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
template <class T>
T smin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  int n;
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  static vector<int> s[1 << 20];
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    s[a].push_back(b);
    s[b].push_back(a);
  }
  static int H[1 << 20];
  static int ok1[1 << 20];
  static int h[1 << 20];
  function<void(int, int)> dfs1 = [&](int node, int prev) {
    set<int> ss;
    ok1[node] = 1;
    for (auto it : s[node])
      if (it != prev)
        dfs1(it, node), ok1[node] &= ok1[it], ss.insert(H[it] + 1);
    ok1[node] &= ss.size() <= 1;
    for (auto it : ss) H[node] += it;
  };
  dfs1(1, 0);
  static int ans[1 << 20];
  for (int i = 1; i <= n; ++i) ans[i] = 2e9;
  function<void(int, int, int)> dfs2 = [&](int node, int prev, int offset) {
    set<int> ss;
    map<int, int> M;
    auto ADD = [&](int number, int v) {
      M[number] += v;
      if (!M[number]) M.erase(M.find(number));
    };
    if (offset != -1) ADD(offset + 1, 1);
    int was = 0;
    int was_ok = 0;
    for (auto it : s[node])
      if (it != prev) {
        ADD(H[it] + 1, 1);
        ++was;
        was_ok += ok1[it];
      }
    if (was_ok == was && M.size() <= 2) {
      ans[node] = 0;
      for (auto it : M) ans[node] += it.first;
    }
    for (auto it : s[node])
      if (it != prev) {
        ADD(H[it] + 1, -1);
        int next_ok = M.size() <= 1 && (was - 1 == was_ok - ok1[it]);
        int next_offset = 0;
        if (next_ok) {
          for (auto it : M) next_offset += it.first;
          if (M.empty()) next_offset = offset + 1;
          dfs2(it, node, next_offset);
        }
        ADD(H[it] + 1, 1);
      }
  };
  dfs2(1, 0, -1);
  int answer = *min_element(ans + 1, ans + 1 + n);
  if (answer <= n)
    cout << answer << '\n';
  else
    puts("-1");
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
