n = read_line.to_i a = STDIN.gets_to_end.split.map(&.to_i) hash = a.zip(0..).to_h que = Deque{0} dist = [nil.as(Int32?)] * (n + 2) dist[0] = -1 while i = que.shift? d = dist[i].not_nil! puts(d) + exit if i == 1 a.each_with_index do |x, j| if (a[i] ^ x).popcount == 1 && dist[j].nil? dist[j] = d + 1 que << j end end end puts -1