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

//package e_contest_9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class treeFolding2 {
	static ArrayList<Integer> adjList[];
	static int n;
	static int [] levels;
	public static void main(String[] args) throws IOException{
		Scanner sc= new Scanner(System.in);
		n =sc.nextInt();
		adjList =new  ArrayList[n];
		for (int i = 0; i < adjList.length; i++) {
			adjList[i] =new ArrayList<Integer>();
		}
		for (int i = 0; i < n-1; i++) {
			int one =sc.nextInt()-1, two =sc.nextInt()-1;
			adjList[one].add(two);
			adjList[two].add(one);
		}
		levels =new int[n];
		Arrays.fill(levels, -1);
		levels[0] = 0;
		Queue<Integer> q =new LinkedList<Integer>();
		q.add(0);
		int idx = 0;
		int deepestLevel =0;
		while(!q.isEmpty()) {
			int top = q.remove();
			int curLevel = levels[top];
			if(curLevel>deepestLevel) {
				deepestLevel = curLevel;
				idx = top;
			}
			for (int i = 0; i < adjList[top].size(); i++) {
				int nxt = adjList[top].get(i);
				if(levels[nxt]==-1)
				{
					levels[nxt] =curLevel+1;
					q.add(nxt);
				}
				
			}
		}
		Arrays.fill(levels, -1);
		q.add(idx);
		levels[idx]=0;
		deepestLevel =0;
		while(!q.isEmpty()) {
			int top = q.remove();
			int curLevel = levels[top];
			if(curLevel>deepestLevel) {
				deepestLevel = curLevel;
			}
			for (int i = 0; i < adjList[top].size(); i++) {
				int nxt = adjList[top].get(i);
				if(levels[nxt]==-1)
				{
					levels[nxt] =curLevel+1;
					q.add(nxt);
				}
				
			}
		}
//		System.out.println(deepestLevel);
		deepestLevel+=1;
		if(deepestLevel%2==0) {
			if(deepestLevel==2) {
				System.out.println(1);
			}else {
			int countRight = deepestLevel/2;
			vis = new boolean[n];
			int idxRight =dfs(idx,countRight);
			vis = new boolean[n];
			int countLeft = deepestLevel/2+1;
			int idxLeft = dfs(idx,countLeft);
//			System.out.println(idxRight+" "+idxLeft);
			leaves =new ArrayList<Integer>();
			vis =new boolean[n];
			dfs2(idxRight, idxLeft);
			
			
			Arrays.fill(levels, -1);
			q.add(idxRight);
			levels[idxRight]=0;
			while(!q.isEmpty()) {
				int top = q.remove();
				int curLevel = levels[top];
				for (int i = 0; i < adjList[top].size(); i++) {
					int nxt = adjList[top].get(i);
					if(levels[nxt]==-1)
					{
						levels[nxt] =curLevel+1;
						q.add(nxt);
					}
					
				}
			}
			
			
			
			int lenPrev = levels[leaves.get(0)];
			boolean good = true;
			for (int i = 1; i < leaves.size(); i++) {
				int lenCur = levels[leaves.get(i)];
				if(lenCur!=lenPrev)
					good = false;
			}
			if(good) {
				leaves =new ArrayList<Integer>();
				vis =new boolean[n];
				dfs2(idxLeft, idxRight);
				Arrays.fill(levels, -1);
				q.add(idxLeft);
				levels[idxLeft]=0;
				while(!q.isEmpty()) {
					int top = q.remove();
					int curLevel = levels[top];
					for (int i = 0; i < adjList[top].size(); i++) {
						int nxt = adjList[top].get(i);
						if(levels[nxt]==-1)
						{
							levels[nxt] =curLevel+1;
							q.add(nxt);
						}
						
					}
				}
				lenPrev = levels[leaves.get(0)];
				good = true;
				for (int i = 1; i < leaves.size(); i++) {
					int lenCur = levels[leaves.get(i)];
					if(lenCur!=lenPrev)
						good = false;
				}
			}
			if(good) {
				while(deepestLevel%2==1&&deepestLevel!=1)
					deepestLevel-=deepestLevel/2;
				System.out.println(deepestLevel-1);
			}else
				System.out.println(-1);
			}
		}else {
			int countRight = deepestLevel/2;
			vis =new boolean[n];
			int idxRight =dfs(idx,countRight);
//			System.out.println(idxRight);
			leaves =new ArrayList<Integer>();
			vis =new boolean[n];
			dfs2(idxRight, -1);
//			System.out.println(leaves.toString());
			HashSet<Integer> hs =new HashSet<Integer>();
			
			Arrays.fill(levels, -1);
			q.add(idxRight);
			levels[idxRight]=0;
			while(!q.isEmpty()) {
				int top = q.remove();
				int curLevel = levels[top];
				for (int i = 0; i < adjList[top].size(); i++) {
					int nxt = adjList[top].get(i);
					if(levels[nxt]==-1)
					{
						levels[nxt] =curLevel+1;
						q.add(nxt);
					}
					
				}
			}
			int first = levels[leaves.get(0)];
			int  last = 0;
			int two = -1;
			
			for (int i = 0; i < leaves.size(); i++) {
				last = levels[leaves.get(i)]; 
				hs.add(last);
//				System.out.println(hs.toString());
				if(first!=last) {
					two = last;
				}
			}
			
			if(hs.size()==1) {
				first+=1;
				while(first%2==1&&first!=1)
					first-=first/2;
				System.out.println(first-1);
			}else if(hs.size()==2) {
				first+=two+1;
				while(first%2==1&&first!=1)
					first-=first/2;
				System.out.println(first-1);
			}else {
				System.out.println(-1);
			}
			
		}
	}
	static ArrayList<Integer> leaves;
	static boolean [] vis;
	static int dfs3(int idx, int parent, int target) {
//		int len = 1;
//		System.out.println(idx+" "+parent+" "+target);
		for (int i = 0; i < adjList[idx].size(); i++) {
			int nxt = adjList[idx].get(i);
			if(nxt==parent)
				continue;
			if(nxt==target)
				return 1;
			int found =dfs3(nxt, idx, target);
			if(found>0)
				return 1 + found;
		}
		return 0;
	}
	static void dfs2(int idx, int leave) {
		int valid = 0;
		vis[idx] =true;
		for (int i = 0; i < adjList[idx].size(); i++) {
			int nxt = adjList[idx].get(i);
			if(vis[nxt]||nxt ==leave)
				continue;
			dfs2(nxt, leave);
			valid++;
		}
		if(valid==0)
			leaves.add(idx);
	}
	static int dfs(int idx, int counter ) {
		if(counter==0)
			return idx;
		vis[idx] = true;
		for (int i = 0; i < adjList[idx].size(); i++) {
			int nxt = adjList[idx].get(i);
			if(vis[nxt])
				continue;
			int poss = dfs(nxt, counter-1);
			if(poss!=-1)
				return poss;
		}
		return -1;
	}
	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();}


	}



}
