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 int INF = 1e9 + 7;
const double PI = atan2(0, -1);
const int MAXN = 2e5 + 5;
vector<int> graph[MAXN];
int d[MAXN];
vector<int> here[MAXN];
bool really_bad[MAXN];
int dfs(int v, int p) {
  bool flag = false;
  for (int to : graph[v]) {
    if (to != p) {
      dfs(to, v);
      if (d[to] == -1) {
        flag = true;
      }
    }
  }
  if (flag) {
    d[v] = -1;
    really_bad[v] = true;
    return 0;
  }
  set<int> arr;
  for (int to : graph[v]) {
    if (to != p) {
      arr.insert(d[to]);
    }
  }
  for (auto pa : arr) {
    here[v].push_back(pa + 1);
  }
  if (((int)(here[v]).size()) == 0) {
    here[v].push_back(0);
    d[v] = 0;
  } else if (((int)(here[v]).size()) == 1) {
    d[v] = here[v][0];
  } else {
    d[v] = -1;
  }
  return 0;
}
int ans = INF;
int upd(vector<int>& arr1, vector<int>& arr2) {
  sort(begin(arr1), end(arr1));
  sort(begin(arr2), end(arr2));
  vector<int> tmp(((int)(arr1).size()) + ((int)(arr2).size()));
  merge(begin(arr1), end(arr1), begin(arr2), end(arr2), tmp.begin());
  tmp.resize(unique(begin(tmp), end(tmp)) - tmp.begin());
  if (((int)(tmp).size()) > 0 && ((int)(tmp).size()) <= 2) {
    int val = accumulate(begin(tmp), end(tmp), 0);
    while (val % 2 == 0) {
      val /= 2;
    }
    ans = min(ans, val);
  }
  return 0;
}
int dfs2(int v, int p, vector<int>& val) {
  if (((int)(val).size()) >= 2) {
    return 0;
  }
  for (int& num : val) {
    ++num;
  }
  if (!really_bad[v]) {
    upd(here[v], val);
  }
  set<int> now;
  for (int num : val) {
    now.insert(num);
  }
  vector<set<int>> rl;
  rl.push_back(set<int>());
  int mem = 0;
  for (int i = ((int)(graph[v]).size()) - 1; i >= 0; --i) {
    int to = graph[v][i];
    if (to != p) {
      rl.push_back(rl.back());
      if (d[to] == -1) {
        mem = i + 1;
        break;
      }
      for (int num : here[to]) {
        rl.back().insert(num + 1);
      }
      if (((int)(rl.back()).size()) > 2) {
        mem = i;
        break;
      }
    } else {
      rl.push_back(rl.back());
    }
  }
  for (int i = 0; i < ((int)(graph[v]).size()); ++i) {
    int to = graph[v][i];
    if (to != p) {
      if (((int)(now).size()) > 2) {
        break;
      }
      if (i + 1 >= mem) {
        vector<int> tmp;
        for (int num : now) {
          tmp.push_back(num);
        }
        for (int num : rl[((int)(graph[v]).size()) - i - 1]) {
          tmp.push_back(num);
        }
        sort(begin(tmp), end(tmp));
        tmp.resize(unique(begin(tmp), end(tmp)) - tmp.begin());
        dfs2(to, v, tmp);
      }
      if (d[to] == -1) {
        break;
      }
      for (int num : here[to]) {
        now.insert(num + 1);
      }
    }
  }
  return 0;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(0, -1);
  vector<int> tmp;
  if (((int)(graph[0]).size()) == 1) {
    tmp.push_back(-1);
  }
  dfs2(0, -1, tmp);
  if (ans == INF) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}
