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

class Node(object):

	__slots__ = ('index', 'neighbors', 'parent', 'depth', 'node_depth_map', 'depth_nodes_map', 'balances', 'unbalance_nodes')

	def __init__(self, index):
		self.index = index
		self.neighbors = []
		self.parent = None
		self.depth = 0
		self.node_depth_map = {}
		self.depth_nodes_map = {}
		self.balances = {}
		self.unbalance_nodes = []

	def __repr__(self):
		return '*%d' % self.index


n = input()
nodes = [Node(i) for i in xrange(n + 1)]
for _ in xrange(n - 1):
	u, v = map(int, raw_input().split())
	nodes[u].neighbors.append(nodes[v])
	nodes[v].neighbors.append(nodes[u])


stack = []
stack_tmp = [nodes[1]]
while stack_tmp:
	node = stack_tmp.pop()
	parent_node = node.parent
	if len(node.neighbors) > 1 or not parent_node:
		for neighbor_node in node.neighbors:
			if neighbor_node != parent_node:
				stack_tmp.append(neighbor_node)
				neighbor_node.parent = node
				stack.append(neighbor_node)


for node in reversed(stack):
	parent_node = node.parent
	parent_node.node_depth_map[node] = depth = node.depth + 1
	if depth in parent_node.depth_nodes_map:
		depth_nodes = parent_node.depth_nodes_map[depth]
	else:
		depth_nodes = parent_node.depth_nodes_map[depth] = []
	depth_nodes.append(node)
	if depth > parent_node.depth:
		parent_node.depth = depth

	balance = not node.unbalance_nodes and len(node.depth_nodes_map) <= 1
	parent_node.balances[node] = balance
	if not balance:
		parent_node.unbalance_nodes.append(node)
del stack


path_count = 0
min_depth = n
stack_tmp = [nodes[1]]
while stack_tmp:
	node = stack_tmp.pop()
	parent_node = node.parent

	next_nodes = []
	depth_count = len(node.depth_nodes_map)
	assert depth_count != 0
	if depth_count == 1:
		if not node.unbalance_nodes:
			depth = node.depth_nodes_map.keys()[0]
			if depth < min_depth:
				min_depth = depth
			path_count += 1
			for child_node in node.neighbors:
				if child_node != parent_node:
					next_nodes.append(child_node)
		elif len(node.unbalance_nodes) >= 2:
			break
		else:
			next_node = node.unbalance_nodes[0]
			if next_node != parent_node:
				next_nodes.append(next_node)
	elif depth_count >= 3:
		break
	else:
		flag1 = 0
		flag2 = False
		candidate_nodes = []
		for depth, child_nodes in node.depth_nodes_map.iteritems():
			if len(child_nodes) >= 2:
				flag1 += 1
				if flag1 == 2:
					break
				for child_node in child_nodes:
					if not node.balances[child_node]:
						flag2 = True
						break
				if flag2:
					break
			else:
				candidate_node = child_nodes[0]
				if candidate_node != parent_node:
					candidate_nodes.append(candidate_node)
		if flag1 == 2 or flag2:
			break
		if len(candidate_nodes) >= 2:
			flag3 = False
			for candidate_node in candidate_nodes:
				flag3 |= node.balances[candidate_node]
			if not flag3:
				break
		next_nodes.extend(candidate_nodes)

	for next_node in next_nodes:
		depth_count = len(node.depth_nodes_map)
		if len(node.depth_nodes_map[node.node_depth_map[next_node]]) == 1:
			depth_count -= 1
		if depth_count > 1:
			continue
		unbalance_nodes_count = len(node.unbalance_nodes)
		if next_node in node.unbalance_nodes:
			unbalance_nodes_count -= 1
		if unbalance_nodes_count > 0:
			continue
		depth = 0
		for child_node, child_depth in node.node_depth_map.iteritems():
			if child_node != next_node:
				if child_depth > depth:
					depth = child_depth
		depth += 1
		next_node.node_depth_map[node] = depth
		if depth in next_node.depth_nodes_map:
			depth_nodes = next_node.depth_nodes_map[depth]
		else:
			depth_nodes = next_node.depth_nodes_map[depth] = []
		depth_nodes.append(node)
		next_node.balances[node] = True

		stack_tmp.append(next_node)


print min_depth if path_count > 0 else -1
