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', '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.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
	if not balance:
		parent_node.unbalance_nodes.append(node)
del stack


min_length = -1
stack_tmp = [nodes[1]]
while stack_tmp:
	node = stack_tmp.pop()

	parent_node = node.parent
	depth_nodes_map = node.depth_nodes_map
	unbalance_nodes = node.unbalance_nodes
	node_depth_map = node.node_depth_map

	if len(unbalance_nodes) >= 2:
		break
	if len(depth_nodes_map) >= 3:
		break
	if not unbalance_nodes:
		length = sum(depth_nodes_map.keys())
		while length & 1 == 0:
			length >>= 1
		if min_length == -1:
			min_length = length
		elif length < min_length:
			min_length = length
		break
	if unbalance_nodes:
		neighbor_node = unbalance_nodes[0]
		if neighbor_node != parent_node:
			depth = 0
			for child_node, child_depth in node_depth_map.iteritems():
				if child_node != neighbor_node:
					if child_depth > depth:
						depth = child_depth
			depth += 1
			neighbor_node.node_depth_map[node] = depth

			if depth in neighbor_node.depth_nodes_map:
				depth_nodes = neighbor_node.depth_nodes_map[depth]
			else:
				depth_nodes = neighbor_node.depth_nodes_map[depth] = []
			depth_nodes.append(node)

			unbalance_nodes_count = len(unbalance_nodes)
			if neighbor_node in unbalance_nodes:
				unbalance_nodes_count -= 1
			balance = True
			if unbalance_nodes_count > 0:
				balance = False
			else:
				depth_count = len(depth_nodes_map)
				if len(depth_nodes_map[node_depth_map[neighbor_node]]) == 1:
					depth_count -= 1
				if depth_count > 1:
					balance = False
			if not balance:
				neighbor_node.unbalance_nodes.append(node)

			stack_tmp.append(neighbor_node)

print min_length