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;
inline long long read() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
int n, ans, x[N], y[N], d[N];
vector<int> e[N];
int son[N], dp[N];
bool flag[N];
inline void dfs(int u, int fa) {
  vector<pair<int, int> > q;
  for (auto v : e[u])
    if (v != fa) {
      dfs(v, u), son[u]++;
      if (son[v] == 1) q.push_back(make_pair(dp[v] + 1, v));
    }
  sort(q.begin(), q.end()), q.push_back(make_pair(0, 0));
  for (register int i = (q.size() - 3); i >= (0); i--)
    if (q[i].first == q[i + 1].first) son[u]--, flag[q[i + 1].second] = 1;
  if (son[u] == 1) dp[u] = q[0].first;
  if (!son[u]) son[u] = dp[u] = 1;
}
inline void Clear() {
  for (register int i = (1); i <= (n); i++) e[i].clear(), son[i] = 0;
}
bool Flag;
int rt, sum;
inline void Dfs(int u, int fa) {
  ans++;
  for (auto v : e[u])
    if (v != fa) Dfs(v, u), son[u]++;
  if (son[u] > 2) Flag = 0;
  if (son[u] == 2 && u != 1) sum++, rt = u;
}
int cnt, len[4];
inline void Dfs(int u, int fa, int dis) {
  if (d[u] == 1) len[++cnt] = dis;
  for (auto v : e[u])
    if (v != fa) Dfs(v, u, dis + 1);
}
int main() {
  n = read();
  for (register int i = (2); i <= (n); i++)
    x[i] = read(), y[i] = read(), e[x[i]].push_back(y[i]),
    e[y[i]].push_back(x[i]);
  dfs(1, 0), Clear();
  for (register int i = (2); i <= (n); i++)
    if (!flag[x[i]] && !flag[y[i]])
      e[x[i]].push_back(y[i]), e[y[i]].push_back(x[i]), d[x[i]]++, d[y[i]]++;
  Flag = 1, Dfs(1, 0), Flag &= (sum <= 1);
  if (!Flag) return puts("-1"), 0;
  if (!rt) {
    while (ans & 1) ans -= (ans >> 1);
    return printf("%d\n", ans - 1), 0;
  }
  Dfs(rt, 0, 0);
  sort(len + 1, len + 1 + cnt);
  if (len[1] == len[2] && len[2] == len[3])
    ans -= len[1] * 2;
  else if (len[1] == len[2])
    ans -= len[1];
  else if (len[2] == len[3])
    ans -= len[2];
  else
    return puts("-1"), 0;
  while (ans & 1) ans -= (ans >> 1);
  printf("%d\n", ans - 1);
}
