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.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.io.DataInputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.HashMap;
import java.util.Comparator;
public class Main
{
	static class Reader
	{
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader()
		{
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException
		{
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException
		{
			byte[] buf = new byte[201]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1)
			{
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException
		{
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException
		{
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException
		{
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			}
			while ((c = read()) >= '0' && c <= '9');

			if (c == '.')
			{
				while ((c = read()) >= '0' && c <= '9')
				{
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException
		{
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException
		{
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException
		{
			if (din == null)
				return;
			din.close();
		}
	}
        static class pair{
         int n,l;pair(int a,int b){n=a;l=b;}
         public String toString(){return n+"-"+l;}
        }
        static LinkedList<Integer> ll[];
        static HashMap<Integer,Integer> hm[];
        static PriorityQueue<pair> pq[];
        static boolean go(pair p,int id){
         boolean r=true;int n=p.n;
                  while(ll[p.n].size()+rc[p.n]<=2){r=false;
                   ListIterator it=ll[p.n].listIterator();
                   while(it.hasNext()){
                    int v=(int)it.next();
                    if(hm[p.n].get(v)==null){r=true;hm[v].put(p.n,1);p.n=v;break;}
                   }if(!r){p.n=-1;break;}++p.l;
                  }pq[id].add(p);
                  if(n==p.n)return false;else return true;
        }
        static int find(int v){
         while(v%2==0)v/=2;return v;
        }
        static int f(int id){//System.out.println(pq[id]+" f");
         Iterator it=pq[id].iterator();
                  int sum=0;
                  while(it.hasNext()){
                   pair pp=(pair)it.next();sum+=pp.l;
                  } return find(sum);
        }
        static int rc[];
        public static void main(String[] args) throws IOException
	{
		Reader s=new Reader();PrintWriter pw=new PrintWriter(System.out);
                int n=s.nextInt();
                ll=new LinkedList[n+1];
                for(int i=0;i<n+1;i++)ll[i]=new LinkedList<>();
                int nc[]=new int[n+1];
                for(int i=0;i<n-1;i++){
                 int u=s.nextInt(),v=s.nextInt();
                 ll[u].add(v);ll[v].add(u);nc[u]++;nc[v]++;
                }
                pq=new PriorityQueue[2];
                for(int i=0;i<2;i++)
                pq[i]=new PriorityQueue<>(10,new Comparator<pair>(){
                 public int compare(pair p1,pair p2){return p1.n==p2.n?p1.l-p2.l:p1.n-p2.n;}
                });
                for(int i=1;i<=n;i++){if(nc[i]==1)pq[0].add(new pair(i,0));}
                hm=new HashMap[n+1];
                for(int i=0;i<n+1;i++)hm[i]=new HashMap<>();rc=new int[n+1];
                int ans=-1,t=1;boolean R=true;
                while(R){t=1-t;R=false;
                 while(!pq[t].isEmpty()){//System.out.println(pq[t]+" "+pq[1-t]);
                 pair p=pq[t].peek();int e=0,L=p.l;
                 o:while(true&&!pq[t].isEmpty()){e++;pq[t].remove(pq[t].peek());
                  Iterator tt=pq[t].iterator();
                  while(tt.hasNext()){
                   pair p1=(pair)tt.next();
                   if(p1.n!=p.n)break o;
                   if(p1.l==L){R=true;tt.remove();rc[p.n]--;}
                   else{pq[1-t].add(new pair(p.n,L));L=p1.l;continue o;} 
                  }
                 }
                 if(e==1){
                  if(p.n!=-1){R=go(p,1-t);}
                  else{pq[t].add(p);ans=f(t);break;}
                 }else pq[1-t].add(new pair(p.n,L));
                 if(e==2&&pq[1-t].size()==2&&pq[t].isEmpty()){
                  ans=f(1-t);break;
                 }
                }
               }pw.write(ans+"");
		pw.flush();pw.close();
	}
}
