from collections import deque n = int(input()) start, end = map(int, input().split()) stones = list(map(int, input().split())) # Create a list of all nodes including start, stones, and end nodes = [start] + stones + [end] total_nodes = len(nodes) end_idx = total_nodes - 1 # Index of the end node distance = [-1] * total_nodes distance[0] = 0 # Start node is at index 0 q = deque([0]) found = False while q: current = q.popleft() # Check if current node is the end node if current == end_idx: found = True break current_val = nodes[current] for other_idx in range(total_nodes): if other_idx == current: continue other_val = nodes[other_idx] # Calculate Hamming distance xor = current_val ^ other_val ham = bin(xor).count('1') if ham <= 1 and distance[other_idx] == -1: distance[other_idx] = distance[current] + 1 q.append(other_idx) if other_idx == end_idx: found = True # Early exit if end is found q = deque() break if distance[end_idx] == -1: print(-1) else: print(max(0, distance[end_idx] - 1))