N = int(input()) s,e = map(int,input().split()) S = [s] + list(map(int,input().split())) + [e] N += 2 def check(X, Y): L = len(bin(max(X,Y))[2:]) X = bin(X)[2:].zfill(L) Y = bin(Y)[2:].zfill(L) cnt = 0 for i in range(L): if X[i] != Y[i]: cnt += 1 if cnt > 1: return False return True G = [[] for i in range(N)] for i in range(N - 1): for j in range(i + 1, N): if check(S[i], S[j]): G[i].append(j) G[j].append(i) from collections import deque q = deque([]) q.append([0, 0]) visited = [False] * N visited[0] = True while q: v, c = q.popleft() if v == N - 1: print(c - 1) break for child in G[v]: if visited[child]: continue visited[child] = True q.append([child, c + 1]) else: print(-1)