n = read_line.to_i s, t = read_line.split.map(&.to_i) a = read_line.split.map(&.to_i) a << s a << t hash = Hash(Int32, Int32).new(n + 2) n.times do |i| hash[a.unsafe_fetch(i)] = i end hash[s] = n hash[t] = n &+ 1 que = Deque{n} dist = Pointer(Int32).malloc(n + 2) dist[n] = 1 while i = que.shift? d = dist[i] ai = a.unsafe_fetch(i) puts(d &- 2) + exit if i == n &+ 1 bit = 1 30.times do if (j = hash[ai ^ bit]?) && dist[j] == 0 dist[j] = d &+ 1 que << j end bit <<= 1 end end puts -1