#yuki1576 from collections import deque n=int(input()) s,e=map(int,input().split()) st=list(map(int,input().split())) dist={x:-1 for x in st} dist[s]=0 dist[e]=-1 d=deque() d.append(s) while d: v=d.popleft() for x in range(30): i=v^(2**x) if i not in dist: continue if dist[i]!=-1: continue dist[i]=dist[v]+1 d.append(i) if dist[e]==-1: print(-1) else: print(dist[e]-1)