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;
using LD = long double;
vector<int> pr;
vector<int> used;
vector<vector<int> > g;
int dfs(int v, int p) {
  pr[v] = p;
  used[v] = 1;
  for (auto to : g[v]) {
    if (to != p) {
      return dfs(to, v);
    }
  }
  return v;
}
bool dfs_check_1(int v, int p, int h, int a) {
  if (used[v] && p != -1) {
    return true;
  }
  for (auto to : g[v]) {
    if (to != p) {
      if (!dfs_check_1(to, v, h + 1, a)) {
        return false;
      }
    }
  }
  if (g[v].size() == 1 && p != -1) {
    return (h == a);
  }
  return true;
}
bool try_solve(int st, int f, int dist) {
  bool ok = true;
  int v = pr[f];
  int a = 1;
  while (v != st) {
    bool res = dfs_check_1(v, -1, 0, a);
    ok = ok && res;
    v = pr[v];
    a++;
  }
  if (ok) {
    return true;
  }
  a = dist - 1;
  v = pr[f];
  ok = true;
  while (v != st) {
    bool res = dfs_check_1(v, -1, 0, a);
    ok = ok && res;
    v = pr[v];
    a--;
  }
  return ok;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout.setf(ios_base::fixed);
  cout.precision(28);
  int n;
  cin >> n;
  g = vector<vector<int> >(n);
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  pr.resize(n, -1);
  used.resize(n, 0);
  int st = 0;
  for (int i = 0; i < n; ++i) {
    if (g[i].size() == 1) {
      st = i;
      break;
    }
  }
  int f = dfs(st, -1);
  int ans = 1e9;
  int v = pr[f];
  int dist = 1;
  while (v != st) {
    v = pr[v];
    dist++;
  }
  bool ok = try_solve(st, f, dist);
  if (ok) {
    if (dist % 2 == 0) {
      ans = dist / 2;
    } else {
      ans = dist;
    }
  }
  if (dist % 2 == 1) {
    if (ans == 1e9) {
      cout << -1;
      return 0;
    }
    cout << ans << "\n";
    return 0;
  }
  int half = (dist / 2) - 1;
  v = pr[f];
  while (half != 0) {
    v = pr[v];
    half--;
  }
  int nst = v;
  vector<int> q = {nst};
  used[nst] = 1;
  for (int i = 0; i < q.size(); ++i) {
    int curv = q[i];
    for (auto to : g[curv]) {
      if (used[to]) {
        continue;
      }
      q.push_back(to);
      pr[to] = curv;
      used[to] = 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    used[i] = 0;
  }
  f = q.back();
  dist = 1;
  used[f] = 1;
  v = pr[f];
  while (v != st) {
    dist++;
    used[v] = 1;
    v = pr[v];
    used[v] = 1;
  }
  used[st] = 1;
  ok = try_solve(st, f, dist);
  if (ok) {
    if (dist % 2 == 0) {
      ans = min(ans, dist / 2);
    } else {
      ans = min(ans, dist);
    }
  }
  if (ans == 1e9) {
    cout << -1;
    return 0;
  }
  cout << ans << "\n";
  return 0;
}
