import sys readline = sys.stdin.readline N = int(readline()) s,g = map(int,readline().split()) A = [s] + list(map(int,readline().split())) + [g] N += 2 def can_connect(X, Y): diff = 0 while X or Y: if (X & 1) ^ (Y & 1): diff += 1 if diff == 2: return False X >>= 1 Y >>= 1 return True G = [[] for i in range(N)] for i in range(N - 1): for j in range(i + 1, N): if can_connect(A[i], A[j]): G[i].append(j) G[j].append(i) visited = [False] * N from collections import deque q = deque([]) q.append([0, 0]) while q: v, cost = q.popleft() if visited[v]: continue visited[v] = True if v == N - 1: print(cost - 1) break for child in G[v]: if visited[child]: continue q.append([child, cost + 1]) else: print(-1)