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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        boolean can;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            List<Integer>[] adj = new List[n];
            for (int i = 0; i < n; i++) {
                adj[i] = new ArrayList<>();
            }
            for (int i = 0; i < n - 1; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                adj[a].add(b);
                adj[b].add(a);
            }

            int[] diameter = new DiameterFinder(n, adj).findDiameter();
            int root = diameter[diameter.length / 2];
            can = true;
            int d = dfs(adj, root, -1);
            if (!can) {
                out.println(-1);
                return;
            }
            while (d % 2 == 0) {
                d /= 2;
            }
            out.println(d);
        }

        private int dfs(List<Integer>[] adj, int root, int parent) {
            List<Integer> depths = new ArrayList<>();
            for (int child : adj[root]) {
                if (child == parent) {
                    continue;
                }
                depths.add(1 + dfs(adj, child, root));
            }
            if (depths.isEmpty()) {
                return 0;
            }
            Collections.sort(depths);
            int numDifferent = 0;
            for (int i = 0; i < depths.size(); i++) {
                if (i == 0 || !depths.get(i).equals(depths.get(i - 1))) {
                    ++numDifferent;
                }
            }
            if (parent < 0) {
                if (numDifferent > 2) {
                    can = false;
                    return 0;
                }
                if (numDifferent == 1) {
                    return depths.get(0);
                }
                return depths.get(0) + depths.get(depths.size() - 1);
            }
            if (numDifferent > 1) {
                can = false;
            }
            return depths.get(0);
        }

        private class DiameterFinder {
            int n;
            List<Integer>[] adj;
            int[] diameter;
            int[] p;
            int[] d;
            int[] q;
            int farthest;

            public DiameterFinder(int n, List<Integer>[] adj) {
                this.n = n;
                this.adj = adj;
                p = new int[n];
                d = new int[n];
                q = new int[n];
            }

            int[] findDiameter() {
                bfs(0);
                bfs(farthest);
                int k = 0;
                for (int v = farthest; v >= 0; v = p[v]) {
                    ++k;
                }
                diameter = new int[k];
                for (int v = farthest; v >= 0; v = p[v]) {
                    --k;
                    diameter[k] = v;
                }
                return diameter;
            }

            void bfs(int s) {
                int qt = 0;
                int qh = 1;
                Arrays.fill(d, -1);
                q[0] = s;
                d[s] = 0;
                p[s] = -1;
                farthest = s;
                while (qt < qh) {
                    int v = q[qt++];
                    for (int u : adj[v]) {
                        if (d[u] < 0) {
                            d[u] = 1 + d[v];
                            p[u] = v;
                            q[qh++] = u;
                            if (d[farthest] < d[u]) {
                                farthest = u;
                            }
                        }
                    }
                }
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

