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.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class treeFolding {
	static int adjList[][];
	static class pair implements Comparable<pair>{
		int val, cost;
		public pair(int v, int c) {
			cost = c;
			val = v;
		}
		public int compareTo(pair p) {
			return cost==p.cost?val-p.val:cost-p.cost;
		}
	}
	static boolean [] vis;
	static int n;
	static boolean trim(int center) {
		HashMap<Integer,Integer> tm =new HashMap<Integer,Integer>();
		int [] roots =new int[n];
		int idx = 0;
		int [] others =new int[n];
		int idx2 =0;
		for (int i = 0; i < adjList[center].length; i++) {
			int nxt =adjList[center][i];
			int size = endSize[nxt];
			
//			System.out.println("hello2");
			if(size>0)
				roots[idx++]=nxt;
			else
				others[idx2++] =nxt;
			if(tm.containsKey(size)) {
				int count = tm.get(size);
				count++;
				tm.put(size, count);
			}else
				tm.put(size,1);
		}
//		System.out.println("helo");
		adjList[center] = new int[tm.size()];
		idx = 0;
		idx2=0;
		for(int key: tm.keySet()) {
			int value = tm.get(key);
//			System.out.println(key+" "+value);
			if(value==0) {
				for (int i = 0; i < idx2; i++) {
					adjList[center][idx++]=(others[i]);
				}
			}else {//=0=0=0=0
				endSize[roots[idx2]]=key;
				adjList[center][idx++]=(roots[idx2++]);
			}
		}
		if(tm.size()>3||tm.size()==3&&idx2==0)
			return false;
		return true;
		}
	static int [] endSize;
public static void main(String[] args) throws IOException{
	Scanner sc= new Scanner(System.in);
	 n =sc.nextInt();
	adjList =new int [n][];
	pair [] inp =new pair[n-1];
	int max = 0;
	int [] count = new int[n];
	for (int i = 0; i < n-1; i++) {
		int one = sc.nextInt()-1;
		int two =sc.nextInt()-1;
		count[one]++;
		count[two]++;
		inp[i] =new pair(one,two);
	}
	for (int i = 0; i < count.length; i++) {
		adjList[i] =new int[count[i]];
		count[i]=0;
	}
	for (int i = 0; i < inp.length; i++) {
		int one = inp[i].val;
		int two = inp[i].cost;
		adjList[one][count[one]++]=(two);
		adjList[two][count[two]++]=(one);
	}
	
		boolean poss =true;
//		Queue<Integer> q = new LinkedList<Integer>();
		int[] q = new int[n];
		int last1 = -1;
		int remove1 = 0;
		int sizeQ1 = 0;
		int[] qThree = new int[n];
		int last = -1;
		int remove =0;
		int sizeQ = 0;
		for (int i = 0; i < adjList.length; i++) {
			if(adjList[i].length==1) {
				q[++last1]=i;
				sizeQ1++;
			}
			if(adjList[i].length>=3) {
				qThree[++last]=i;
				sizeQ++;
			}
		}
//		System.out.println(q.toString());
		endSize = new int[n];
		int ans = 0;
		while(sizeQ1!=0) {
		
			int cur = q[remove++];
			if(remove==n)
				remove=0;
			sizeQ1--;
			int parent = adjList[cur][0];
//			System.out.println((cur+1)+" "+(1+parent));
			if(endSize[parent]!=0) {
				int total = endSize[parent]+1;
				while(total%2==1&&total!=1) {
					total-=total/2;
				}
			System.out.println(total-1);
			}else {
			int size = 1;
			while(true) {
//				System.out.println((cur+1)+" "+(1+parent));
				if(adjList[parent].length>=3) {
					endSize[cur] = size;
					break;
				}
				if(adjList[parent].length==1) {
					endSize[cur] = size;
					break;
				}
				int idx = 0;
				for (int i = 0; i < adjList[parent].length; i++) {
					if(adjList[parent][i]!=cur)
						idx = i;
				}
				cur = parent;
				parent = adjList[parent][idx];
				size++;
			}
			}
		}
		
		int[] counter =new int[n];
		int time=0;//
//		System.out.println(Arrays.toString(endSize));
		while(true&&sizeQ>0) {
			
//			System.out.println(qThree.size());
//		System.out.println(Arrays.toString(endSize));
			
//			int counterBefore = qThree.size();
			if(sizeQ==1) {
				int center = qThree[remove++];
				if(remove==n)
					remove = 0;
				sizeQ = 0;
				poss = trim(center);
				if(poss) {
//					0=0=0=8=0
//					System.out.println(adjList[center]+ " " +center);
//					System.out.println(endSize[8]+" "+endSize[4]);
				if(adjList[center].length==1) {
					System.out.println(endSize[adjList[center][0]]);
				}else if(adjList[center].length>2){
					System.out.println(-1);
				}else {
					int one = endSize[adjList[center][0]];
					int two = endSize[adjList[center][1]];
					int total = 1+one+two;
					while(total%2==1&&total!=1) {
						total-=total/2;
					}
					System.out.println(total-1);
				}
				}
					break;
				}
			int center = qThree[remove++];
			if(remove==n)
				remove = 0;
			sizeQ--;
			 poss = trim(center);
			boolean found = false;
			if(adjList[center].length>2) {
				qThree[++last]=center;
				if(last==n-1)
					last=-1;
			}
			
			time++;
			if(counter[center]+sizeQ==time||!poss)
				break;
			counter[center]=time;
		}//1 2 3
		if(sizeQ>0||!poss)
			System.out.println(-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();}


}


}
