from collections import deque def main(): twos = [1] for i in range(40): twos.append(twos[-1]*2) twos = set(twos) #print(twos) N = int(input()); INF = float("inf") N += 2 start,end = map(int,input().split()) stone = [start] + list(map(int,input().split())) + [end] G = [[] for _ in range(N)] for i in range(N): for j in range(i+1,N): k = stone[i]^stone[j] #print(i,j,k) if k in twos: G[i].append(j) G[j].append(i) #print(G) D = [-1]*N Q = deque([]) Q.append(0) D[0] = 0 while Q: v = Q.popleft() for u in G[v]: if D[u] != -1: continue D[u] = D[v] + 1 Q.append(u) #print(D,N) if D[N-1] == -1: print(-1) else: print(D[N-1] - 1) if __name__ == '__main__': main()