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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class ProblemE {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);
	static int n;
	static ArrayList<Integer> adjList[], depth[];
	static boolean[] isLeaf;

	static int check(int i) {
		boolean onediff = true;
		TreeSet<Integer> set = new TreeSet<Integer>();
		for (Integer v : depth[i]) {
			set.add(v);
			if (set.size() > 2)
				return -1;
		}
		int ans = 0;
		for (Integer v : set)
			ans += v;
		return ans;

	}

	public static void main(String[] args) throws IOException {
		n = sc.nextInt();
		adjList = new ArrayList[n];
		depth = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adjList[i] = new ArrayList<>();
			depth[i] = new ArrayList<>();
		}

		for (int i = 0; i < n - 1; i++) {
			int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
			adjList[x].add(y);
			adjList[y].add(x);
		}
		Queue<Integer> q1 = new LinkedList<Integer>();
		Queue<Integer> q2 = new LinkedList<Integer>();
		int d = 2; // hold the depth ;
		boolean visited[] = new boolean[n];
		for (int i = 0; i < n; i++)
			if (adjList[i].size() == 1) {
				q1.add(i);
				visited[i] = true;
			}
		while (!q1.isEmpty()) {
			while (!q1.isEmpty()) {
				int u = q1.poll();
				for (Integer v : adjList[u]) {
					depth[v].add(d);
					if (!visited[v])
						q2.add(v);
				}
				visited[u] = true;
			}
			d++;
			q1 = q2;
			q2 = new LinkedList<>();
		}
		boolean found = true;
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int x = check(i);
			if (x != -1) {
				ans = Math.min(check(i), ans);
				found = true;
			}
		}
		
		pw.println(found ? ans : -1);
		pw.flush();
		pw.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();
		}

	}
}
