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.Iterator;
import java.util.Collection;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.stream.Stream;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Optional;
import java.io.BufferedReader;
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;
        MyBufferedReader in = new MyBufferedReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, MyBufferedReader in, PrintWriter out) {
            int n = in.getAnInt();

            ArrayList<Map<Integer, Integer>> depths = new ArrayList<>();
            ArrayList<ArrayList<Integer>> nbrs = new ArrayList<>();
            for (int i = 0; i <= n; i++) {
                depths.add(new TreeMap<>());
                nbrs.add(new ArrayList<>());
            }

            for (int i = 0; i < n - 1; i++) {
                int[] data = in.getALineOfInts(2);
                int v1 = data[0];
                int v2 = data[1];
                nbrs.get(v1).add(v2);
                nbrs.get(v2).add(v1);
            }

            getDepthsBelow(1, -1, nbrs, depths, true);
            if (depths.stream().anyMatch(d -> d.size() > 2)) {
                out.println(-1);
                return;
            }

            addDepthAbove(1, -1, 0, nbrs, depths);
            if (depths.stream().anyMatch(d -> d.size() > 2)) {
                out.println(-1);
                return;
            }

            int diam = 0;
            for (int i = 1; i <= n; i++) {
                Set<Integer> currDepths = depths.get(i).keySet();
                int maxCurr = 0;
                for (int d : currDepths) {
                    maxCurr += d;
                }
                diam = Math.max(diam, maxCurr);
            }

            if (diam % 2 == 1) {
                out.println(diam);
                return;
            }

            for (int i = 1; i <= n; i++) {
                Set<Integer> currDepths = depths.get(i).keySet();
                if (currDepths.contains(diam / 2)) {
                    for (int d : currDepths) {
                        if (d != diam / 2) {
                            diam = diam / 2 + d;
                            while (diam % 2 == 0) {
                                diam /= 2;
                            }

                            out.println(diam);
                            return;
                        }
                    }
                }
            }

            while (diam % 2 == 0) {
                diam /= 2;
            }

            out.println(diam);
        }

        private void addDepthAbove(int node, int prev, int acc, ArrayList<ArrayList<Integer>> nbrs,
                                   ArrayList<Map<Integer, Integer>> depths) {
            Map<Integer, Integer> nodeDepths = depths.get(node);

            Optional<Integer> optional = depths.get(node).keySet().stream().max
                (Integer::compareTo);
            int nodeMax = 0;
            if (optional.isPresent()) {
                nodeMax = optional.get();
            }

            for (int nbr : nbrs.get(node)) {
                if (nbr != prev) {
                    optional = depths.get(nbr).keySet().stream().max
                        (Integer::compareTo);
                    int childMax = 0;
                    if (optional.isPresent()) {
                        childMax = optional.get();
                    }

                    int nextMax;
                    if (childMax + 1 != nodeMax || nodeDepths.get(nodeMax) > 1) {
                        nextMax = nodeMax;
                    } else {
                        int other = nodeDepths.keySet().iterator().next();
                        if (other == childMax + 1) {
                            nextMax = 0;
                        } else {
                            nextMax = other;
                        }
                    }

                    addDepthAbove(nbr, node, 1 + Math.max(acc, nextMax), nbrs, depths);
                }
            }

            if (acc > 0) {
                nodeDepths.put(acc, nodeDepths.containsKey(acc) ? nodeDepths.get(acc) + 1 : 1);
            }
        }

        private int getDepthsBelow(int node, int prev, ArrayList<ArrayList<Integer>> nbrs,
                                   ArrayList<Map<Integer, Integer>> depths, boolean updateDepths) {
            int max = 0;
            for (int nbr : nbrs.get(node)) {
                if (nbr != prev) {
                    int childRes = getDepthsBelow(nbr, node, nbrs, depths, updateDepths);
                    if (updateDepths) {
                        if (depths.get(node).containsKey(childRes)) {
                            depths.get(node).put(childRes, depths.get(node).get(childRes) + 1);
                        } else {
                            depths.get(node).put(childRes, 1);
                        }
                    }
                    max = Math.max(max, childRes);
                }
            }

            return max + 1;
        }

    }

    static class MyBufferedReader {
        BufferedReader in;

        public MyBufferedReader(InputStream s) {
            this.in = new BufferedReader(new InputStreamReader(s));
        }

        public int getAnInt() {
            int res = -1;
            try {
                res = Integer.parseInt(new StringTokenizer(in.readLine()).nextToken());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }

        public int[] getALineOfInts(int numExpected) {
            int[] res = new int[numExpected];
            StringTokenizer st = null;
            try {
                st = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < numExpected; i++)
                res[i] = Integer.parseInt(st.nextToken());
            return res;
        }

    }
}

