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(" "))) que = deque([]) que.append((0, start)) while len(que): cnt, now = que.popleft() if hamming_distance(now, end) == 1: print(cnt) break for stone in stones: if hamming_distance(now, stone) == 1: que.append((cnt+1, stone)) stones.remove(stone) else: print(-1)