#include <bits/stdc++.h>
using namespace std;
long double PI = acosl(-1.0);
int main() {
  int n;
  cin >> n;
  vector<vector<int>> G(n);
  vector<int> deg(n, 0);
  vector<int> w(n, 1);
  vector<vector<int>> hang(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  queue<int> Q;
  for (int i = 0; i < n; ++i) {
    deg[i] = G[i].size();
    if (deg[i] == 1) {
      Q.push(i);
    }
  }
  int visited = 0;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    if (hang[v].size() >= 1) {
      if (hang[v].size() > 1) {
        sort(hang[v].begin(), hang[v].end());
        hang[v].erase(unique(hang[v].begin(), hang[v].end()), hang[v].end());
      }
      if (hang[v].size() == 1) {
        w[v] += hang[v][0];
        hang[v].clear();
      }
    }
    if (hang[v].size() > 0) {
      continue;
    }
    int wv = w[v];
    ++visited;
    if (visited == n) {
      break;
    }
    w[v] = 0;
    for (int to : G[v]) {
      if (w[to] == 0) {
        continue;
      }
      hang[to].push_back(wv);
      --deg[to];
      if (deg[to] == 1) {
        Q.push(to);
      }
    }
  }
  int id = -1;
  for (int i = 0; i < n; ++i) {
    if (w[i] > 0) {
      if (id != -1) {
        cout << -1 << endl;
        return 0;
      }
      id = i;
    }
  }
  if (hang[id].size() > 2) {
    cout << -1 << endl;
    return 0;
  }
  if (hang[id].size() == 2) {
    int sum = hang[id][0] + hang[id][1];
    while (sum % 2 == 0) {
      sum /= 2;
    }
    cout << sum << endl;
  } else {
    int sum = hang[id][0];
    while (sum % 2 == 0) {
      sum /= 2;
    }
    cout << sum << endl;
  }
  return 0;
}
