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 double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
template <class T>
T sqr(T x) {
  return x * x;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
int type, n, d[MAXN], pa[MAXN];
vector<int> adj[MAXN], leaf;
void dfs1(int u, int p) {
  if (!~p)
    d[u] = 0;
  else
    d[u] = d[p] + 1;
  pa[u] = p;
  int check = 1;
  for (int i = 0; i < ((int)(adj[u]).size()); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    dfs1(v, u);
    check = 0;
  }
  if (!type && check) leaf.push_back(u);
}
pair<int, int> dfs2(int u, int p) {
  int check = 1;
  int find = -1;
  for (int i = 0; i < ((int)(adj[u]).size()); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    pair<int, int> cur = dfs2(v, u);
    if (cur.first == 0) {
      return make_pair(0, -1);
    }
    check = 0;
    if (!~find) {
      find = cur.second;
    } else {
      if (find != cur.second) {
        return make_pair(0, -1);
      }
    }
  }
  if (check) return make_pair(1, 1);
  return make_pair(1, find + 1);
}
int solve(int u, int v) {
  dfs1(u, -1);
  if (d[v] % 2) return -1;
  int tmp = d[v] / 2;
  while (tmp) {
    v = pa[v];
    tmp--;
  }
  vector<pair<int, int> > AN;
  for (int i = 0; i < ((int)(adj[v]).size()); i++) {
    pair<int, int> cur = dfs2(adj[v][i], v);
    if (cur.first) AN.push_back(cur);
  }
  if (((int)(AN).size()) < ((int)(adj[v]).size()))
    return -1;
  else {
    int cnt = 0;
    for (int i = 1; i < ((int)(AN).size()); i++) {
      if (AN[i].second != AN[0].second) cnt++;
    }
    if (cnt == 0)
      return AN[0].second;
    else if (cnt == ((int)(AN).size()) - 1)
      return AN[0].second + AN[1].second;
    else if (cnt == 1) {
      for (int i = 1; i < ((int)(AN).size()); i++) {
        if (AN[i].second != AN[0].second) return AN[0].second + AN[i].second;
      }
    } else
      return -1;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(0, -1);
  if (((int)(leaf).size()) == 1) {
    cout << n - 1;
    return 0;
  }
  type = 1;
  int ans = -1;
  for (int i = 0; i < ((int)(leaf).size()); i++) {
    for (int j = i + 1; j < ((int)(leaf).size()) && j < i + 3; j++) {
      ans = solve(leaf[i], leaf[j]);
      if (~ans) {
        cout << ans;
        return 0;
      }
    }
  }
  cout << -1;
}
