Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex v, and two disjoint (except for v) paths of equal length a0 = v, a1, ..., ak, and b0 = v, b1, ..., bk. Additionally, vertices a1, ..., ak, b1, ..., bk must not have any neighbours in the tree other than adjacent vertices of corresponding paths. After that, one of the paths may be merged into the other, that is, the vertices b1, ..., bk can be effectively erased:

<image>

Help Vanya determine if it possible to make the tree into a path via a sequence of described operations, and if the answer is positive, also determine the shortest length of such path.

Input

The first line of input contains the number of vertices n (2 ≤ n ≤ 2·105).

Next n - 1 lines describe edges of the tree. Each of these lines contains two space-separated integers u and v (1 ≤ u, v ≤ n, u ≠ v) — indices of endpoints of the corresponding edge. It is guaranteed that the given graph is a tree.

Output

If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path.

Examples

Input

6
1 2
2 3
2 4
4 5
1 6


Output

3


Input

7
1 2
1 3
3 4
1 5
5 6
6 7


Output

-1

Note

In the first sample case, a path of three edges is obtained after merging paths 2 - 1 - 6 and 2 - 4 - 5.

It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1 - 3 - 4 and 1 - 5 - 6, since vertex 6 additionally has a neighbour 7 that is not present in the corresponding path.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

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

    static class TaskE {
        private int[] dp1;
        private int[] dp2;
        private Edge[] first;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            first = new Edge[n];
            dp1 = new int[n];
            dp2 = new int[n];

            for (int i = 0; i < n - 1; ++i) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                new Edge(u, v);
                new Edge(v, u);
            }

            dfs1(0, -1);
            dfs2(0, -1);
            int maxDist = Integer.MAX_VALUE;
            for (int i = 0; i < n; ++i) {
                dp2[i] = Math.max(dp2[i], dp1[i]);
                if (dp2[i] < maxDist) {
                    maxDist = dp2[i];
                }
            }
//        System.err.print(Arrays.toString(dp2));
            ArrayList<Integer> roots = new ArrayList<>();
            for (int i = 0; i < n; ++i) {
                if (dp2[i] == maxDist) {
                    roots.add(i);
                }
            }
            if (roots.size() == 2) {
                int u = dfs(roots.get(0), roots.get(1));
                int v = dfs(roots.get(1), roots.get(0));
                if (u != -1 && u == v) {
                    out.println(maxDist * 2 - 1);
                } else {
                    out.println(-1);
                }
            } else {
                boolean noSolution = false;
                TreeSet<Integer> children = new TreeSet<>();
                int root = roots.get(0);
//            System.err.println("root = " + root);
                for (Edge e = first[root]; e != null; e = e.next) {
                    int cl = dfs(e.to, root) + 1;
//                System.err.println("CL = " + cl);
                    if (cl == 0) {
                        noSolution = true;
                        break;
                    }
                    children.add(cl);
                }
                if (children.size() > 2) {
                    noSolution = true;
                }
                if (noSolution) {
                    out.println(-1);
                    return;
                }

                int value = children.first() + children.last();
                while (value % 2 == 0) {
                    value /= 2;
                }
                out.println(value);
            }
        }

        private int dfs(int x, int fa) {
            int childLength = -1;
            for (Edge e = first[x]; e != null; e = e.next) {
                if (e.to == fa) {
                    continue;
                }
                int cl2 = dfs(e.to, x) + 1;
                if (cl2 == 0) {
                    return -1;
                }
                if (childLength == -1) {
                    childLength = cl2;
                }
                if (cl2 != childLength) {
                    return -1;
                }
            }
            return childLength == -1 ? 0 : childLength;
        }

        private void dfs1(int x, int fa) {
            dp1[x] = 0;
            for (Edge e = first[x]; e != null; e = e.next) {
                if (e.to == fa) {
                    continue;
                }
                dfs1(e.to, x);
                dp1[x] = Math.max(dp1[x], dp1[e.to] + 1);
            }
        }

        private void dfs2(int x, int fa) {
            List<Integer> children = new ArrayList<>();

            for (Edge e = first[x]; e != null; e = e.next) {
                if (e.to == fa) {
                    continue;
                }
                children.add(e.to);
            }

            int current = dp2[x];
            for (Integer child : children) {
                dp2[child] = Math.max(dp2[child], current + 1);
                current = Math.max(current, dp1[child] + 1);
            }

            current = dp2[x];
            for (int i = children.size() - 1; i >= 0; --i) {
                int child = children.get(i);
                dp2[child] = Math.max(dp2[child], current + 1);
                current = Math.max(current, dp1[child] + 1);
            }

            for (Integer child : children) {
                dfs2(child, x);
            }
        }

        class Edge {
            int to;
            Edge next;

            Edge(int from, int to) {
                this.to = to;
                this.next = first[from];
                first[from] = this;
            }

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new UnknownError();
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}

