from collections import Counter from collections import deque def hmg_d(a, b): count = Counter(list(bin(a ^ b))) if count["1"] == 1: return True else: return False n = int(input()) start, end = map(int,input().split()) stone = list(map(int,input().split())) if hmg_d(start, end): print(0) exit() stone_dict = {} stone_dict[start] = 0 for i in stone: stone_dict[i] = 0 queue = deque() queue.append(start) while queue: v = queue.popleft() for i in stone: if hmg_d(v, i): if stone_dict[i] == 0: stone_dict[i] = stone_dict[v] + 1 queue.append(i) if hmg_d(i, end): print(stone_dict[i]) exit() print(-1)