from collections import deque #ハミング距離 def hamming(a,b): x=bin(a^b) d=0 for i in x[2:]: d+=int(i) return d n=int(input()) start,end=map(int,input().split()) stone=list(map(int,input().split())) x=[start]+stone+[end] #BFS dist=[False]*(n+2) que=deque([0]) dist[0]=0 while que: v=que.popleft() for u in range(n+2): if hamming(x[v],x[u])==1 and dist[u]==False: dist[u]=dist[v]+1 que.append(u) res=dist[-1] if not res: print(-1) else: print(res-1)