n,S,G,*a, = map(int,open(0).read().split()) n += 2 a += [S,G] g = [[] for _ in range(n)] for i in range(n): for j in range(n): v = a[i]^a[j] if v and v&(v-1)==0: g[i].append(j) d = [-1]*n q = [n-2] d[n-2] = 0 for v in q: for i in g[v]: if d[i] == -1: d[i] = d[v] + 1 q.append(i) print(max(-1,d[-1]-1))