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

//Codeforces Round 397 (Div. 2)
import java.io.*;
import java.util.*;

public class TaskE {	
	
	static int x;
	
	static int outer(int i, int p, ArrayList<ArrayList<Integer>> a) {
		int l = -1;
		int lx = i;				
		for (Integer j : a.get(i)) {
			if (j != p) {
				int k = outer(j, i, a);				
				if (k > l) {
					l = k;
					lx = x;
				}
			}
		}
		x = lx;
		return l + 1;
	}
	
	
	static ArrayList<Integer> path(int i, int p, int x, ArrayList<ArrayList<Integer>> a) {
		ArrayList<Integer> l = null;
		if (i == x) {
			l = new ArrayList<Integer>();
			l.add(x);
			return l;
		} else {			
			for (Integer j : a.get(i)) {
				if (j != p) {
					l = path(j, i, x, a);
					if (l != null) break;
				}
			}
			if (l != null) {
				l.add(i);				
			}
			return l;
		}
	}
	
	
	static int fold(int i, int p, ArrayList<ArrayList<Integer>> a) {
		int l = -1;		
		for (Integer j : a.get(i)) {
			if (j != p) {
				int k = fold(j, i, a);
				if (k == -1) {
					l = -2;
					break;
				}
				if (l == -1) {
					l = k;
				} else if (l != k) {
					l = -2;
					break;					
				}
			}
		}
		return l + 1;		
	}
	
	public static void main (String[] args) throws IOException {
		FastScanner fs = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);		
		
		int n = fs.nextInt();		
		
        ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();
		for (int i = 0; i < n; i++) {
			a.add(new ArrayList<Integer>());
		}
		
		for (int i = 0; i < n-1; i++) {
            int x = fs.nextInt() - 1;
			int y = fs.nextInt() - 1;
			a.get(x).add(y);
			a.get(y).add(x);
        }        
		
		outer(0, -1, a);
		int o1 = x;		
		int l = outer(o1, -1, a);
		int o2 = x;		
		ArrayList<Integer> p = path(o1, -1, o2, a);
		
		
		if ((l & 1) == 0) {
			int m = p.get(l >> 1);
			int f1 = -1;
			int f2 = -1;			
			for (Integer j : a.get(m)) {
				int f = fold(j, m, a);
				if (f == -1) {
					f1 = -1;
					break;
				} else {
					if (f1 == -1) {
						f1 = f;
					} else {
						if (f1 != f) {
							if (f2 == -1) {
								f2 = f;
							} else if (f2 != f) {
								f1 = -1;
								break;
							}
						}
					}
				}
			}			
			
			
			if (f1 == -1) {
				l = f1;
			} else {
				f1++;
				f2++;				
				l = f1 + f2;
				while ((l & 1) == 0) {
					l >>= 1;
				}
			}
		} else {
			int m1 = p.get(l >> 1);
			int m2 = p.get((l >> 1) + 1);
			int f = fold(m1, m2, a);
			if (f != -1) {
				f = fold(m2, m1, a);
			}
			if (f == -1) {
				l = f;
			}			
		}
		
		pw.println(l);
        		
		pw.close();		
	}
	
	static class FastScanner {
        BufferedReader reader;
        StringTokenizer tokenizer;        
        FastScanner(InputStream i) {
            reader = new BufferedReader(new InputStreamReader(i));
            tokenizer = new StringTokenizer("");
        }
        String next() throws IOException {
            while(!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine());
            return tokenizer.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }        
    }
}