#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200003];
bool first = true, got = false;
int dfs(int v, int p) {
  int n1 = 0, n2 = 0, p1 = 0, p2 = 0, v1 = 0, v2 = 0;
  for (vector<int>::iterator it = adj[v].begin(), ite = adj[v].end(); it != ite;
       ++it) {
    if (*it == p) continue;
    int t = dfs(*it, v);
    if (got) return t;
    if (t == -1) return -1;
    if (n1 == 0) {
      n1 = t;
      ++p1;
      v1 = *it;
    } else if (n1 == t)
      ++p1;
    else if (n2 == 0) {
      n2 = t;
      ++p2;
      v2 = *it;
    } else if (n2 == t)
      ++p2;
    else
      return -1;
  }
  if (p == 0) {
    got = true;
    return (n1 + n2);
  }
  if (p2 == 0) return n1 + 1;
  if (!first) return -1;
  first = false;
  int t = dfs(v, 0);
  got = true;
  return t;
}
int main() {
  int n, i, j, k, v = -1, mx = -1;
  cin >> n;
  for (i = 1; i < n; ++i) {
    cin >> j >> k;
    adj[j].push_back(k);
    adj[k].push_back(j);
    int s1 = adj[j].size(), s2 = adj[k].size();
    if (s1 > mx) {
      v = j;
      mx = adj[j].size();
    } else if (s2 > mx) {
      v = k;
      mx = adj[k].size();
    }
  }
  int t;
  if (mx <= 2)
    t = n - 1;
  else
    t = dfs(v, 0);
  while ((t & 1) == 0) t = (t >> 1);
  cout << t << endl;
  return 0;
}
