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 int N = 200005, INF = 9999999;
const long long P = 1e9 + 7;
template <typename T>
inline void read(T& first, char s = getchar()) {
  first = 0;
  while (s > '9' || s < '0') s = getchar();
  while (s <= '9' && s >= '0') first = first * 10 + s - '0', s = getchar();
}
vector<int> g[N];
vector<int> q;
bool vis[N];
int n;
pair<int, int> dfs1(int first, int fa) {
  pair<int, int> ret = make_pair(first, 0);
  for (int i = (int)(0); i < (int)(g[first].size()); i++) {
    if (g[first][i] != fa && !vis[g[first][i]]) {
      pair<int, int> now = dfs1(g[first][i], first);
      if (now.second > ret.second) ret = now;
    }
  }
  ret.second++;
  return ret;
}
bool getq(int first, int second, int fa) {
  if (first == second) {
    q.push_back(second);
    return 1;
  }
  for (int i = (int)(0); i < (int)(g[first].size()); i++) {
    if (g[first][i] != fa && !vis[g[first][i]]) {
      if (getq(g[first][i], second, first)) {
        q.push_back(first);
        return 1;
      }
    }
  }
  return 0;
}
void clr(int first, int fa) {
  vis[first] = 1;
  for (int i = (int)(0); i < (int)(g[first].size()); i++) {
    if (g[first][i] != fa && !vis[g[first][i]]) {
      clr(g[first][i], first);
    }
  }
}
bool FUCK;
int dfs2(int first, int fa) {
  int len = 0;
  for (int i = (int)(0); i < (int)(g[first].size()); i++) {
    if (g[first][i] != fa && !vis[g[first][i]]) {
      int add = dfs2(g[first][i], first);
      if (FUCK) return 0;
      if (len == 0)
        len = add;
      else {
        if (len != add) {
          FUCK = 1;
          return 0;
        }
      }
    }
  }
  return len + 1;
}
bool chian() {
  for (int first = (int)(1); first <= (int)(n); first++) {
    int num = 0;
    for (int i = (int)(0); i < (int)(g[first].size()); i++) {
      if (!vis[g[first][i]]) num++;
    }
    if (num > 2) return 0;
  }
  return 1;
}
void j8() {
  int siz = q.size();
  for (int w = 1; w < siz / 2; w++) {
    int first = q[w];
    for (int i = (int)(0); i < (int)(g[first].size()); i++) {
      if (g[first][i] != q[w - 1] && g[first][i] != q[w + 1] &&
          !vis[g[first][i]]) {
        int len = dfs2(g[first][i], first);
        if (len == w) {
          clr(g[first][i], first);
        } else
          FUCK = 1;
        if (FUCK) {
          cout << -1 << endl;
          return;
        }
      }
    }
  }
}
int main() {
  read(n);
  for (int i = (int)(1); i < (int)(n); i++) {
    int first, second;
    read(first), read(second);
    g[first].push_back(second), g[second].push_back(first);
  }
  while (true) {
    if (chian()) {
      int ans = 0;
      for (int i = (int)(1); i <= (int)(n); i++) {
        if (!vis[i]) ans++;
      }
      if (!(ans & 1)) {
        cout << ans - 1 << endl;
        return 0;
      }
    }
    int f;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (!vis[i]) {
        f = i;
        break;
      }
    int first = dfs1(f, 0).first;
    int second = dfs1(first, 0).first;
    q.clear();
    getq(first, second, 0);
    j8();
    if (FUCK) return 0;
    reverse(q.begin(), q.end());
    j8();
    if (FUCK) return 0;
    if (q.size() & 1) {
      int w = q.size() / 2;
      int first = q[w], len = 0;
      for (int i = (int)(0); i < (int)(g[first].size()); i++) {
        if (g[first][i] != q[w - 1] && g[first][i] != q[w + 1] &&
            !vis[g[first][i]]) {
          int add = dfs2(g[first][i], first);
          if (FUCK) {
            cout << -1 << endl;
            return 0;
          }
          if (add == w) {
            clr(g[first][i], first);
          } else if (len == 0) {
            len = add;
          } else if (len == add) {
            clr(g[first][i], first);
          } else {
            cout << -1 << endl;
            return 0;
          }
        }
      }
      for (int w = 0; w < q.size() / 2; w++) {
        vis[q[w]] = 1;
      }
    }
  }
  return 0;
}
