n = read_line.to_i s, t = read_line.split.map(&.to_i) a = Pointer(Int32).malloc(n + 2) a.copy_from(read_line.split.map(&.to_i).to_unsafe, n) a[n] = s a[n + 1] = t hash = Hash(Int32, Int32).new(n + 2) n.times do |i| hash[a[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[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