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.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Abood3C {

	static int n;
	static ArrayList<Integer>[] Tree;
	static TreeMap<Integer, Integer>[] maps;
	static int[] p;
   
	
	static int dfs(int u, int parent){
		p[u] = parent;
		
		
		TreeSet<Integer> set = new TreeSet<>();
		int max = 0;
		for (int i = 0; i < Tree[u].size(); i++) {
			int v = Tree[u].get(i);
			if(p[u] != v){
				int a = dfs(v, u);
				set.add(a);
				if(a == -1)
					a = -2;
				maps[u].put(v,1 + a);
				max = Math.max(max, a + 1);
			}
		}
		
		if(set.contains(-1))
			return -1;
		
		if(set.size() > 1)
			return -1;
		
		return max;
	}
	
	static int solve(int u, int top){
		System.out.println("Hi");
		int cN = 0;
		int negNode = -1;
		int color1= -1;
		int color2 = -1;
		int color1N = -1;
		int color2N = -1;
		
		boolean can = true;
		
		for (int i = 0; i < Tree[u].size(); i++) {
			int v = Tree[u].get(i);
			if(v != p[u]){
				int color = maps[u].get(v);
				
				if(color == -1){
					cN++;
					negNode = v;
				}
				
				if(color1 == -1)
					color1 = color;
				else if(color2 == -1 && color != color1)
					color2 = color;
				
				if(color1 != -1 && color2 != -1 && color != color1 && color != color2){
					can = false;
				}
				
				if(color == color1){
					color1N = v;
				}
				
				if(color == color2){
					color2N = v;
				}
				
			}
		}
		
//		System.out.println(u + 1 + " " + cN + " " +color1 + " " + color2 + " " +top);
		
		if(color1 == -1 && color2 == -1 && top == -1)
			return 0;
		
		if(color1 == -1 && color2 == -1)
			return top;
		
		if(cN > 1 || !can || cN > 0 && color2 != -1)
			return -1;
		
		if(cN == 0 && color2 == -1 && (top == -1 || top == color1))
			return color1;
		
		if(cN == 0 && color2 == -1)
			return solve(color1N, top + 1);
		
		if(cN > 0 && color2 == -1 && (top == color1 || top == -1))
			return solve(negNode, color1 + 1);
		
		if(cN > 0)
			return -1;
		
		 if(top == -1)
			return solve(color1N, color2 + 1);
		
		 if(top == color1)
			 return solve(color2N, top + 1);
		 
		 if(top == color2)
			 return solve(color1N, top + 1);
		 
		 return -1;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		Tree = new ArrayList[n];

		maps = new TreeMap[n];
		
		for (int i = 0; i < n; i++){
			Tree[i] = new ArrayList<>();
			maps[i] = new TreeMap<>();
		}
		
		for (int i = 0; i < n - 1; i++) 
			Tree[sc.nextInt() - 1].add(sc.nextInt() - 1);
		
		
		p = new int[n];

		dfs(0, -1);
		
		int ans = solve(0, -1);
		while(ans > 0 && ans % 2 == 0)
			ans /= 2;
		
		
		System.out.println(ans);
		
		


		out.flush();
		out.close();
	}


	static class Scanner 



	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}


		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}



	}

}
