from collections import deque def bfs(G, s, N): Q = deque([]) dist = [-1] * N par = [-1] * N dist[s] = 0 for u in G[s]: par[u] = s dist[u] = 1 Q.append(u) while Q: u = Q.popleft() for v in G[u]: if dist[v] != -1: continue dist[v] = dist[u] + 1 par[v] = u Q.append(v) return dist N = int(input()) s, g = map(int, input().split()) X = [s] + list(map(int, input().split())) + [g] D = dict() N += 2 for i in range(N): D[X[i]] = i G = [[] for i in range(N)] for i in range(N): for j in range(35): now = X[i] ^ (1 << j) if now in D: u = D[now] G[i].append(u) DD = bfs(G, 0, N) print(DD[-1] - 1) if DD[-1] != -1 else print(-1)