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;
template <typename T>
int sz(vector<T> const& v) {
  return v.size();
}
template <typename T>
T gcd(T a, T b) {
  T m;
  while (b) {
    m = a % b;
    a = b;
    b = m;
  }
  return a;
}
static const int N = 300000 + 8;
vector<int> g[N];
int parent[N];
int depth[N];
bool visit[N];
int ch[N];
int n;
int ans;
int solve() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
    ++ch[u];
    ++ch[v];
  }
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  if (n == 2) {
    printf("1\n");
    return 0;
  }
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (ch[i] == 1) {
      ch[i] = 0;
      parent[i] = g[i][0];
      visit[i] = true;
      depth[i] = 1;
      q.push(i);
    }
  }
  ans = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (parent[v] == 0) continue;
    int p = parent[v];
    depth[p] = max(depth[p], 1 + depth[v]);
    --ch[p];
    if (ch[p] == 1) {
      parent[p] = 0;
      for (int i = 0; i < g[p].size(); ++i) {
        int to = g[p][i];
        if (visit[to]) continue;
        parent[p] = to;
        break;
      }
      ch[p] = 0;
      visit[p] = true;
      q.push(p);
      if (parent[p] == 0) {
        int min_depth = n + n;
        int max_depth = 0;
        int na = 0, nb = 0;
        for (int i = 0; i < g[p].size(); ++i) {
          int to = g[p][i];
          min_depth = min(min_depth, depth[to]);
          max_depth = max(max_depth, depth[to]);
        }
        if (min_depth == max_depth) {
          ans = min_depth;
        } else {
          for (int i = 0; i < g[p].size(); ++i) {
            int to = g[p][i];
            if (depth[to] == min_depth) ++na;
            if (depth[to] == max_depth) ++nb;
          }
          if (na + nb != g[p].size()) {
            puts("-1");
            return 0;
          }
          ans = min_depth + max_depth;
        }
      } else {
        int min_depth = n + n;
        int max_depth = 0;
        for (int i = 0; i < g[p].size(); ++i) {
          int to = g[p][i];
          if (to == parent[p]) continue;
          min_depth = min(min_depth, depth[to]);
          max_depth = max(max_depth, depth[to]);
        }
        if (g[p].empty()) continue;
        if (min_depth != max_depth) {
          puts("-1");
          return 0;
        }
      }
    }
  }
  if (ans % 2 == 0) ans /= 2;
  printf("%d\n", ans);
  return 0;
}
int main() {
  ::std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solve();
  return 0;
}
