class ReversalGame {
    private $numbers;

    public function __construct() {
        $this->initialize();
    }

    public function play() {
        $i = 0;
        $moveCount = 0;
        while (true) {
            echo json_encode($this->numbers) . ;
            echo ;
            $i = intval(rtrim(fgets(STDIN), ));
            if ($i == 99) {
                break;
            }
            if ($i < 2 || $i > 9) {
                echo ;
            } else {
                $moveCount++;
                $this->reverse($i);
                if ($this->isSorted()) {
                    echo ;
                    break;
                }
            }

        }
    }

    private function reverse($position) {
        array_splice($this->numbers, 0, $position, array_reverse(array_slice($this->numbers, 0, $position)));
    }

    private function isSorted() {
        for ($i = 0; $i < count($this->numbers) - 1; ++$i) {
            if ($this->numbers[$i] > $this->numbers[$i + 1]) {
                return false;
            }
        }
        return true;
    }

    private function initialize() {
        $this->numbers = range(1, 9);
        while ($this->isSorted()) {
            shuffle($this->numbers);
        }
    }

}

$game = new ReversalGame();
$game->play();