from collections import deque n = int(input()) start, end = map(int, input().split(" ")) stones = list(map(int, input().split(" "))) def hamming_distance(a: int, b: int) -> int: x = a ^ b return bin(x)[2:].count("1") 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 hamming_distance(now, stone) == 1: que.append((cnt+1, stone)) else: print(-1)