n = read_line.to_i a = read_line.split.map &.to_i can = (0...12).select { |d| a.all? { |ai| [0, 2, 4, 5, 7, 9, 11].includes?((ai - d) % 12) } } puts can.size == 1 ? can[0] : -1