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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeSet;

public class TreeFolding { // gonna get time limit but who caaaaares
	public static void main(String[] args) throws NumberFormatException, IOException {
		HPAllInOne OfficeJet = new HPAllInOne();
		int n = Integer.parseInt(OfficeJet.scan());
		int[] fre = new int[n+1];
		HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
		for(int i = 0 ; i < n-1 ; i++){
			String[] in = OfficeJet.scan().split("\\s+");
			int u = Integer.parseInt(in[0]), v = Integer.parseInt(in[1]);
			fre[u]++; fre[v]++;
			if(!map.containsKey(u))
				map.put(u, new ArrayList<>());
			if(!map.containsKey(v))
				map.put(v, new ArrayList<>());
			map.get(u).add(v);
			map.get(v).add(u);
		}
		ArrayList<Integer> id = new ArrayList<>();
		for(int i = 0 ; i < n+1 ; i++)
			if(fre[i] == 1)
				id.add(i);
		ArrayDeque<Integer> q = new ArrayDeque<>();
		for(int currID : id){
			q.add(currID); q.add(0);
			boolean[] visited = new boolean[n+1];
			visited[currID] = true;
			TreeSet<Integer> set = new TreeSet<>();
			while(!q.isEmpty()){
				int curr = q.poll(), dist = q.poll();
				ArrayList<Integer> adj = map.get(curr);
				boolean went = false;
				for(int i : adj)
					if(!visited[i]){
						visited[i] = true;
						q.add(i); q.add(dist+1);
						went = true;
					}
				if(!went)
					set.add(dist);
			}
			int res = set.pollFirst();
			if(set.size() == 0){
				OfficeJet.Print(res);
				OfficeJet.OutOfInk();
				return;
			}
		}
		OfficeJet.Print(-1);
		OfficeJet.OutOfInk();
	}
	static class HPAllInOne{
		HPCopyMachine c = new HPCopyMachine();
		HPPrinter p = new HPPrinter();
		public String scan() throws IOException {
			return c.readLine();
		}
		public char[][] CopySpreadSheet(int n, int m) throws IOException{
			char[][] SpreadSheet = new char[n][m];
			for(int i = 0 ; i < n ; i++)
				SpreadSheet[i] = c.readLine().toCharArray();
			return SpreadSheet;
		}
		public void NewInkCartridge(){
			p.flush();
		}
		public void OutOfInk() {
			p.close();
		}
		public void Print(Object o){
			p.println(o);
		}
	}
	static class HPCopyMachine extends BufferedReader{
		public HPCopyMachine(){
			super(new InputStreamReader(System.in));
		}
	}
	static class HPPrinter extends PrintWriter{
		public HPPrinter(){
			super(System.out);
		}
	}
}
