N = int(input()) start ,end = map(int,input().split()) stone = set(list(map(int,input().split()))) s = set() from collections import deque import sys q = deque() q.append((start,0)) s.add(start) m = max(stone) k = 1 while 1 << k <= m: k += 1 while len(q): now,d = q.popleft() for j in range(k): next = now ^ (1 << j) if next == end: print(d) exit() if next in stone and next not in s: s.add(next) q.append((next,d + 1)) print(-1)