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>
const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
long long int INFINF = (long long int)1e18;
int debug = 0;
long double PI = acos(-1.0);
using namespace std;
int bit_count(long long int _x) {
  long long int _ret = 0;
  while (_x) {
    if (_x % 2 == 1) _ret++;
    _x /= 2;
  }
  return _ret;
}
int bit(long long int _mask, int _i) {
  return (_mask & (1ll << _i)) == 0 ? 0 : 1;
}
int add(int a, int b, int m = MOD) {
  int x = a + b;
  while (x >= m) x -= m;
  while (x < 0) x += m;
  return x;
}
int sub(int a, int b, int m = MOD) {
  int x = a - b;
  while (x < 0) x += m;
  while (x >= m) x -= m;
  return x;
}
int mul(int a, int b, int m = MOD) {
  long long int x = a * 1ll * b;
  x %= m;
  while (x < 0) x += m;
  return (int)x;
}
int ldtoint(long double x) { return (int)(x + 0.5); }
long long int ldtolli(long double x) { return (long long int)(x + 0.5); }
int powermod(long long int _a, long long int _b, int _m = MOD) {
  long long int _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = mul(_r, _a, _m);
    _b >>= 1;
    _a = mul(_a, _a, _m);
  }
  return _r;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << "[" << p.first << "," << p.second << "]";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  bool first = true;
  for (T it : v) {
    if (!first) os << ", ";
    first = false;
    os << it;
  }
  os << "]";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, set<T>& v) {
  os << "[";
  bool first = true;
  for (T it : v) {
    if (!first) os << ", ";
    first = false;
    os << it;
  }
  os << "]";
  return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, map<T1, T2>& v) {
  os << "[";
  bool first = true;
  for (pair<T1, T2> it : v) {
    if (!first) os << ", ";
    first = false;
    os << "(" << it.first << "," << it.second << ")";
  }
  os << "]";
  return os;
}
template <class T>
void parr(T a[], int s, int e) {
  cout << "[";
  for (int i = s; i < e; i++) cout << a[i] << ", ";
  cout << a[e] << "]\n";
}
int N;
vector<int> G[200010];
int f[200010], g[200010];
int cnt[200010];
int distinct = 0;
set<int> global;
int zerocnt;
int parent[200010];
void ADD(int x) {
  if (x == 0) {
    zerocnt++;
    return;
  }
  if (cnt[x] == 0) distinct++, global.insert(x);
  cnt[x]++;
}
void REM(int x) {
  if (x == 0) {
    zerocnt--;
    return;
  }
  if (cnt[x] == 1) distinct--, global.erase(x);
  cnt[x]--;
}
void dfs1(int u, int p) {
  parent[u] = p;
  int childs = 0;
  for (int v : G[u]) {
    if (v == p) continue;
    dfs1(v, u);
    childs++;
  }
  if (childs == 0) {
    f[u] = 1;
    return;
  }
  set<int> second;
  bool fff = true;
  for (int v : G[u]) {
    if (v == p) continue;
    if (f[v] != 0)
      second.insert(f[v]);
    else
      fff = false;
  }
  if (!fff) {
    f[u] = 0;
    return;
  }
  if (second.size() == 1) f[u] = (*second.begin()) + 1;
}
void dfs2(int u, int p) {
  int childs = 0;
  for (int v : G[u]) {
    if (v == p) continue;
    childs++;
  }
  if (childs == 0) {
    return;
  }
  if (u != 1) ADD(g[u]);
  for (int v : G[u]) {
    if (v == p) continue;
    ADD(f[v]);
  }
  for (int v : G[u]) {
    if (v == p) continue;
    REM(f[v]);
    if (distinct == 1 && zerocnt == 0) {
      g[v] = (*global.begin()) + 1;
    } else if (distinct == 0) {
      g[v] = 1;
    }
    ADD(f[v]);
  }
  for (int v : G[u]) {
    if (v == p) continue;
    REM(f[v]);
  }
  if (u != 1) REM(g[u]);
  for (int v : G[u]) {
    if (v == p) continue;
    dfs2(v, u);
  }
}
int main() {
  if (0) {
    freopen("input.txt", "r", stdin);
    debug = 1;
  }
  srand(time(NULL));
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  int ans = INF;
  for (int u = 1; u <= N; u++) {
    set<int> second;
    bool fff = true;
    if (g[u] == 0) fff = false;
    for (int v : G[u])
      if (f[v] == 0 && v != parent[u]) fff = false;
    if (!fff) continue;
    second.insert(g[u]);
    for (int v : G[u])
      if (v != parent[u]) second.insert(f[v]);
    if (second.size() == 1) {
      ans = min(ans, *second.begin());
    } else if (second.size() == 2) {
      int t = 0;
      for (int y : second) t += y;
      ans = min(ans, t);
    }
  }
  if (ans == INF)
    cout << -1;
  else
    cout << ans;
  return 0;
}
