#include <bits/stdc++.h>
using namespace std;
vector<int> mp[200001];
int cur, arr[200001], oans = -1;
pair<int, int> dfs1(int k, int p) {
  pair<int, int> ret(1, k);
  for (size_t i = 0; i < mp[k].size(); ++i)
    if (mp[k][i] != p) {
      pair<int, int> tmp = dfs1(mp[k][i], k);
      if (tmp.first + 1 > ret.first) ret = make_pair(tmp.first + 1, tmp.second);
    }
  return ret;
}
bool dfs2(int k, int p, int exp) {
  arr[++cur] = k;
  if (k == exp) return true;
  for (size_t i = 0; i < mp[k].size(); ++i)
    if (mp[k][i] != p) {
      if (dfs2(mp[k][i], k, exp)) return true;
    }
  --cur;
  return false;
}
int dfs3(int k, int p) {
  int ret = 0;
  for (size_t i = 0; i < mp[k].size(); ++i)
    if (mp[k][i] != p) {
      int res = dfs3(mp[k][i], k);
      if (res == -1) return -1;
      if (!ret) ret = res;
      if (res != ret) return -1;
    }
  return ret + 1;
}
void check(int root) {
  set<int> st;
  for (size_t i = 0; i < mp[root].size(); ++i) {
    int val = dfs3(mp[root][i], root);
    if (val == -1) return;
    st.insert(val);
  }
  if (st.size() > 2u) return;
  int ans = 0;
  for (set<int>::iterator i = st.begin(); i != st.end(); ++i) ans += *i;
  while (ans % 2 == 0) ans /= 2;
  if (oans == -1 || ans < oans) oans = ans;
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int t1, t2;
    scanf("%d%d", &t1, &t2);
    mp[t1].push_back(t2);
    mp[t2].push_back(t1);
  }
  int a = dfs1(1, -1).second;
  int b = dfs1(a, -1).second;
  dfs2(a, -1, b);
  check(arr[cur / 2]);
  check(arr[cur / 2 + 1]);
  printf("%d", oans);
  return 0;
}
