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.*;
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; }}
}