import math from collections import deque def is_ham1(a,b): if math.log2(a^b).is_integer(): return True else: return False n = int(input()) s,g = map(int,input().split()) ishi = deque(map(int,input().split())) ishi.appendleft(g) q=deque() q.append([s,0]) S=set() S.add(s) while q: a = q.popleft() S.add(a[0]) for b in ishi: if a[0]==b: continue if not is_ham1(a[0],b): continue if b in S: continue if b==g: print(a[1]) exit() q.append([b,a[1]+1]) print(-1)