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 long long Max = 2e5 + 10;
long long n;
set<long long> adj[Max];
long long par[Max];
pair<long long, long long> bfs(long long start) {
  queue<long long> q;
  q.push(start);
  vector<long long> dist(n + 1, n + 1);
  dist[start] = 0;
  par[start] = -1;
  while (!q.empty()) {
    const long long node = q.front();
    q.pop();
    for (long long to : adj[node]) {
      if (dist[to] > 1 + dist[node]) {
        dist[to] = 1 + dist[node];
        par[to] = node;
        q.push(to);
      }
    }
  }
  long long mx = -1;
  long long farNode;
  for (long long i = 1; i <= n; ++i) {
    if (dist[i] < n + 1 && dist[i] > mx) {
      mx = dist[i];
      farNode = i;
    }
  }
  return {farNode, mx};
}
bool dfs(long long node, long long par, long long depth,
         long long currTgtDepth) {
  if (adj[node].size() == 1) {
    if (depth != currTgtDepth) return false;
  }
  for (long long to : adj[node]) {
    if (to == par) continue;
    if (!dfs(to, node, depth + 1, currTgtDepth)) return false;
  }
  return true;
}
bool dfs1(long long node, long long par) {
  if (adj[node].size() > 2) return false;
  for (long long to : adj[node]) {
    if (to == par) continue;
    if (!dfs1(to, node)) return false;
  }
  return true;
}
long long solve(vector<pair<long long, long long>> edges) {
  for (auto &p : edges) {
    if (p.first == 0 || p.second == 0) continue;
    adj[p.first].insert(p.second);
    adj[p.second].insert(p.first);
  }
  pair<long long, long long> far = bfs(edges[0].first);
  far = bfs(far.first);
  vector<long long> diameter;
  long long curr = far.first;
  vector<bool> onDiam(n + 1, false);
  diameter.push_back(curr);
  onDiam[curr] = true;
  while (par[curr] != -1) {
    curr = par[curr];
    diameter.push_back(curr);
    onDiam[curr] = true;
  }
  if (diameter.size() >= 3 && diameter.size() % 2 == 1) {
    const long long root = diameter[diameter.size() / 2];
    const long long to1 = diameter[diameter.size() / 2 - 1];
    const long long to2 = diameter[diameter.size() / 2 + 1];
    if (dfs1(to1, root) && dfs1(to2, root)) {
      set<long long> badNodes;
      for (long long i = diameter.size() / 2 + 1; i < diameter.size(); ++i) {
        badNodes.insert(diameter[i]);
      }
      vector<pair<long long, long long>> newEdges;
      for (auto &p : edges) {
        if (badNodes.count(p.first)) continue;
        if (badNodes.count(p.second)) continue;
        newEdges.push_back(p);
      }
      for (auto &p : edges) {
        adj[p.first].erase(p.second);
        adj[p.second].erase(p.first);
      }
      return solve(newEdges);
    }
  }
  vector<long long> tgtHeight(n + 1);
  for (long long i = 0; i < (long long)diameter.size(); ++i) {
    curr = diameter[i];
    tgtHeight[curr] = min(i, (long long)diameter.size() - i - 1);
  }
  bool possible = true;
  for (long long curr : diameter) {
    for (long long to : adj[curr]) {
      if (onDiam[to]) continue;
      if (!dfs(to, curr, 1, tgtHeight[curr])) {
        possible = false;
        break;
      }
    }
    if (!possible) break;
  }
  for (auto &p : edges) {
    adj[p.first].erase(p.second);
    adj[p.second].erase(p.first);
  }
  if (possible) return diameter.size();
  return -1;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<pair<long long, long long>> edges;
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    edges.push_back({u, v});
  }
  long long size = solve(edges);
  if (size != -1) {
    while (size > 1 && size % 2 == 1) {
      size = (size + 1) / 2;
    }
    cout << size - 1 << '\n';
  } else
    cout << "-1\n";
  return 0;
}
