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