import sys N = int(input()) start,end = map(int,input().split()) S = list(map(int,input().split())) S = [start] + S + [end] E = [[] for _ in range(N+2)] A = [pow(2,i) for i in range(30)] A.append(0) A = set(A) for i in range(N+1): for j in range(i+1,N+2): if S[i] ^ S[j] in A: E[i].append(j) E[j].append(i) visited = [0] * (N+2) que1 = {0} que2 = set() visited[0] = 1 cnt = 0 while que1: for q in que1: if q == N+1: print(cnt-1) sys.exit() for e in E[q]: if visited[e] != 1: visited[e] = 1 que2.add(e) que1,que2 = que2,que1 que2.clear() cnt += 1 print(-1)