local bxor = bit.bxor local f = {} do local mul = 1 while true do f[mul] = true mul = mul * 2 if 1000000007 < mul then break end end end local n = io.read("*n") local a = {} a[1], a[2] = io.read("*n", "*n") for i = 3, n + 2 do a[i] = io.read("*n") end n = n + 2 local len = {} for i = 1, n do len[i] = -1 end len[1] = 0 local tasks = {1} local done = 0 while done < #tasks do done = done + 1 local src = tasks[done] for dst = 1, n do if len[dst] < 0 then if f[bxor(a[src], a[dst])] then if dst == 2 then print(len[src]) os.exit() end len[dst] = len[src] + 1 table.insert(tasks, dst) end end end end print(-1)