from collections import defaultdict, deque from itertools import combinations def main(): _ = int(input()) st, gl = map(int, input().split()) a = [st] + list(map(int, input().split())) + [gl] edge = defaultdict(list) for u, v in combinations(a, 2): if bin(u ^ v).count('1') == 1: edge[u].append(v) edge[v].append(u) q = deque() q.append(st) dist = defaultdict(lambda: -1) dist[st] = 0 while q: v = q.popleft() for i in edge[v]: if i == gl: exit(print(dist[v])) if dist[i] == -1: dist[i] = dist[v] + 1 q.append(i) print(-1) if __name__ == "__main__": main()