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.*;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
       ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));
        //ConsoleIO io = new ConsoleIO(new FileReader("D:\\fbhc\\fighting_all_the_zombies_example_input.txt"), new PrintWriter(new File("D:\\fbhc\\out.txt")));
        new Main(io).solve();
        io.close();
    }
    ConsoleIO io;
    Main(ConsoleIO io) {
        this.io = io;
    }

    long MOD = 1_000_000_007;
    int N, M, W, K, Q;
    List<List<Integer>> gr = new ArrayList<>();

    public void solve() {
        int  n = io.ri();
        for(int i = 0;i<n;i++)gr.add(new ArrayList<>());
        for(int i = 0;i<n-1;i++){
            int u = io.ri()-1;
            int v = io.ri()-1;
            gr.get(u).add(v);
            gr.get(v).add(u);
        }
        par = new int[n];
        vis = new boolean[n];
        hei = new int[n];
        dfs(0,-1,0);
        int n1 = -1;
        int mh= 0;
        for(int i = 0;i<n;i++)if(hei[i]>mh){
            mh = hei[i];
            n1 = i;
        }
        par = new int[n];
        hei = new int[n];
        dfs(n1, -1, 0);
        int n2 = -1;
        mh= 0;
        for(int i = 0;i<n;i++)if(hei[i]>mh){
            mh = hei[i];
            n2 = i;
        }

        vis[n2] = true;
        for(int cur = par[n2];cur!=-1;){
            vis[cur] = true;
            cur = par[cur];
        }

        used = new int[n+3];
        boolean even = mh%2==0;
        int half = mh/2;
        int res = even?half:mh;
        for(int cur = par[n2], lev = 1;cur!=-1;lev++) {
            List<Integer> ch = gr.get(cur);
            int need = Math.min(lev, mh - lev);
            int plus = -1;
            for (int i = 0; i < ch.size(); i++) {
                int v = ch.get(i);
                if (!vis[v]) {
                    int k = can(v, cur);
                    if (k == -1) {
                        io.writeLine("-1");
                        return;
                    }
                    if (even && lev == half) {
                        if (k != need) {
                            if (plus == -1) plus = k;
                            else if (plus != k) {
                                io.writeLine("-1");
                                return;
                            }
                        }
                    } else {
                        if (k != need) {
                            io.writeLine("-1");
                            return;
                        }
                    }
                }
            }
            if (plus != -1) res += plus;
            cur = par[cur];
        }
        while(res%2==0)res/=2;
        io.writeLine(res+"");
    }

    int[] par;
    boolean[] vis;
    int[] hei;

    int ppp = 3;
    int[] used;

    int can(int cur, int p){
        ppp++;
        List<Integer> ch = gr.get(cur);
        int have = 0;
        for (int i = 0; i < ch.size(); i++) {
            int v = ch.get(i);
            if (v != p) {
                int k = can(v, cur);
                if(k==-1)return -1;
                if(have==0)have = k;
                else if(have!=k)return -1;
            }
        }
        return have+1;
    }

    void dfs(int cur, int p, int h) {
        par[cur] = p;
        hei[cur] = h;
        List<Integer> ch = gr.get(cur);
        for (int i = 0; i < ch.size(); i++) {
            int v = ch.get(i);
            if (v != p) {
                dfs(v, cur, h+1);
            }
        }
    }

}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(Reader reader, PrintWriter writer){br = new BufferedReader(reader);out = writer;}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
    public char readSymbol() {
        try {
            while (true) {
                int c = br.read();
                if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
                    return (char) c;
                }
            }
        } catch (Exception ex) {
            return 0;
        }
    }
    //public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}
}