import heapq def main(): n = int(input()) start, end = map(int, input().split()) stones = list(map(int, input().split())) # Nodes: [start, end, stone1, stone2, ...] nodes = [start, end] + stones m = len(nodes) # Total nodes: n + 2 # Build adjacency list adj = [[] for _ in range(m)] for i in range(m): for j in range(i + 1, m): x = nodes[i] y = nodes[j] z = x ^ y if z == 0: adj[i].append(j) adj[j].append(i) else: if (z & (z - 1)) == 0: adj[i].append(j) adj[j].append(i) # Dijkstra's algorithm to find minimal stone types INF = float('inf') cost = [INF] * m cost[0] = 0 # start node is at index 0 heap = [] heapq.heappush(heap, (0, 0)) found = False while heap: current_cost, u = heapq.heappop(heap) if u == 1: # end node is at index 1 print(current_cost) found = True break if current_cost > cost[u]: continue for v in adj[u]: # Check if the node is a stone (index >= 2) if v >= 2: new_cost = current_cost + 1 else: new_cost = current_cost if new_cost < cost[v]: cost[v] = new_cost heapq.heappush(heap, (new_cost, v)) if not found: print(-1) if __name__ == "__main__": main()