from collections import deque def hamming_distance(a: int, b: int) -> int: x = a ^ b return bin(x)[2:].count("1") n = int(input()) start, end = map(int, input().split(" ")) stones = list(map(int, input().split(" "))) visited = [False] * n que = deque([]) que.append((0, start)) while len(que): cnt, now = que.popleft() if hamming_distance(now, end) == 1: print(cnt) break for i in range(n): stone = stones[i] if visited[i]: continue if hamming_distance(now, stone) == 1: visited[i] = True que.append((cnt+1, stone)) else: print(-1)