def checkhamming(n, m): return bin(n ^ m).count('1') N = int(input()) start, end = map(int, input().split()) stones = list(map(int, input().split())) stones.append(end) q = [[start, 0]] while len(q): # print(q) now, count = q.pop(0) if count > len(stones)+1: break # print(now, count) for stone in stones: if checkhamming(now, stone) <= 1 and now != stone: if stone == end: print(count) exit() else: q.append([stone, count+1]) print(-1)