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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int n, root, ans;

vec <int> dia;
vec <int> stk;

struct Graph {
    bool stk[N];
    vec <int> adj[N];
    vec <int> con[N];
} graph;

void input() {
    cin >> n;
    for(int i = 1; i < n; ++i) {
        int u; cin >> u;
        int v; cin >> v;
        graph.adj[u].pb(v);
        graph.adj[v].pb(u);
    }
}

pii dfs(int u, int h) {
    graph.stk[u] = 1;
    pii res = {h, u};
    for(int v: graph.adj[u]) {
        if(graph.stk[v]) {
            continue;
        }
        res = max(res, dfs(v, h + 1));
    }
    graph.stk[u] = 0;
    return res;
}

void diam(int u, int t) {
    stk.pb(u);
    graph.stk[u] = 1;
    if(u == t) {
        dia = stk;
    }
    for(int v: graph.adj[u]) {
        if(graph.stk[v]) {
            continue;
        }
        diam(v, t);
    }
    graph.stk[u] = 0;
    stk.pop_back();
}

bool check(int u, int h) {
    graph.stk[u] = 1;
    bool leaf = 1;
    for(int v: graph.adj[u]) {
        if(graph.stk[v]) {
            continue;
        }
        leaf = 0;
        if(!check(v, h + 1)) {
            return 0;
        }
        for(int e: graph.con[v]) {
            graph.con[u].pb(e);
        }
    }
    if(leaf) {
        if(n > 20000 && u == root) {
            cout << "wtf\n";
        }
        graph.con[u].pb(h);
    }
    sort(all(graph.con[u]));
    graph.con[u].erase(unique(all(graph.con[u])), graph.con[u].end());
    if(u != root && len(graph.con[u]) >= 2 || len(graph.con[u]) >= 3) {
        if(n > 20000) {
            cout << root << ":\n";
            cout << u << " --> " << len(graph.con[u]) << "\n";
            for(int e: graph.con[u]) {
                cout << e << " ";
            }
            cout << "\n";
        }
        return 0;
    }
    graph.stk[u] = 0;
    return 1;
}

int get_diam() {
    int a = dfs(1, 0).yy;
    int b = dfs(a, 0).yy;
    diam(a, b);
    return dia[(len(dia) - 1) / 2];
}

void solve() {
    root = get_diam();
    if(!check(root, 0)) {
        cout << "-1\n";
        return;
    }
    for(int e: graph.con[root]) {
        ans += e;
    }
    while(ans % 2 == 0) {
        ans /= 2;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}
