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;
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long ext_gcd(long long A, long long B, long long *X, long long *Y) {
  long long x2, y2, x1, y1, x, y, r2, r1, q, r;
  x2 = 1;
  y2 = 0;
  x1 = 0;
  y1 = 1;
  for (r2 = A, r1 = B; r1 != 0;
       r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
    q = r2 / r1;
    r = r2 % r1;
    x = x2 - (q * x1);
    y = y2 - (q * y1);
  }
  *X = x2;
  *Y = y2;
  return r2;
}
inline long long modInv(long long a, long long m) {
  long long x, y;
  ext_gcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1 % m, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
inline int STRLEN(char *s) {
  int p = 0;
  while (s[p]) p++;
  return p;
}
inline long long SQRT(long long a) {
  long long v = sqrt(a);
  if (((v) * (v)) == a)
    return v;
  else if (((v + 1) * (v + 1)) == a)
    return v + 1;
  else if (((v + 2) * (v + 2)) == a)
    return v + 2;
  else
    return -1;
}
const int inf = 10000000;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
const long long mod = 1000000007;
const long long modInv2 = 500000004;
int N;
vector<int> Graph[300005];
int parent[300005];
bool linear = true;
int ed1, ed2, dis = 0;
void DFS1(int u, int par, int cnt) {
  if (cnt > dis) {
    dis = cnt;
    ed1 = u;
  }
  for (int i = 0; i < Graph[u].size(); i++) {
    int v = Graph[u][i];
    if (v == par) continue;
    DFS1(v, u, cnt + 1);
  }
}
void DFS2(int u, int par, int cnt) {
  if (cnt > dis) {
    dis = cnt;
    ed2 = u;
  }
  int cc = 0;
  for (int i = 0; i < Graph[u].size(); i++) {
    int v = Graph[u][i];
    if (v == par) continue;
    DFS2(v, u, cnt + 1);
    cc++;
    if (cc > 1) linear = false;
  }
}
void DFS5(int u, int par) {
  for (int i = 0; i < Graph[u].size(); i++) {
    int v = Graph[u][i];
    if (v == par) continue;
    parent[v] = u;
    DFS5(v, u);
  }
}
int findRoot() {
  DFS5(ed1, ed1);
  int u = ed2;
  int cnt = 0;
  while (true) {
    u = parent[u];
    cnt++;
    if (cnt == dis / 2) return u;
  }
  return -1;
}
int same = 0, other = 0;
int otherDis = 0;
void DFS3(int u, int par, int cnt) {
  bool f = false;
  for (int i = 0; i < Graph[u].size(); i++) {
    int v = Graph[u][i];
    if (v == par) continue;
    DFS3(v, u, cnt + 1);
    f = true;
  }
  if (f == false) {
    if (cnt == dis / 2)
      same++;
    else {
      other++;
      otherDis = cnt;
    }
    if (cnt > dis / 2) other = 5;
  }
}
int solve() {
  dis = 0;
  DFS1(1, 1, 0);
  dis = 0;
  DFS2(ed1, ed1, 0);
  if (linear == true) {
    if (dis % 2 == 0) return dis / 2;
    return N - 1;
  }
  if (dis % 2 != 0) return -1;
  int root = findRoot();
  if (root == -1) return -1;
  DFS3(root, root, 0);
  if (other > 1) return -1;
  return dis / 2 + otherDis;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    Graph[u].push_back(v);
    Graph[v].push_back(u);
  }
  cout << solve() << endl;
  return 0;
}
