def popcount(x): return bin(x).count("1") def Hamming(x,y): return popcount(x^y) #================================================== from collections import deque N=int(input()) S,G=map(int,input().split()) A=list(map(int,input().split())) V=[S,G]+A Q=deque([0]) X=[-1]*(N+2); X[0]=0 while Q: x=Q.popleft() for y in range(N+2): if Hamming(V[x],V[y])==1 and X[y]==-1: X[y]=X[x]+1 Q.append(y) print(X[1]-1 if X[1]!=-1 else -1)