def Hamming(x,y): return bin(x^y).count("1") #================================================== from collections import deque N=int(input()) S,G=map(int,input().split()) A=list(map(int,input().split())) V=[S,G]+A V_set=set(V) V_ind={v:i for i,v in enumerate(V)} E=[[] for _ in range(N+2)] for i in range(N+2): w=1 for _ in range(30): if V[i]^w in V_set: E[i].append(V_ind[V[i]^w]) w<<=1 X=[-1]*(N+2); X[0]=0 Q=deque([0]) while Q: x=Q.popleft() for y in E[x]: if X[y]==-1: X[y]=X[x]+1 Q.append(y) print(X[1]-1 if X[1]!=-1 else -1)