<?php
# 入力
fscanf(STDIN, '%d', $n);
$a = [];
$max = 0;
$max2 = 0;
$max_key = [];
foreach(range(0, $n - 1) as $i) {
    $n = intval(trim(fgets(STDIN)));
    $a[] = $n;
    if ($max < $n) {
        $max2 = $max;
        $max = $n;
        $max_key = [$i];
    } elseif($max === $n) {
        $max_key[] = $i;
    }
}
$cnt_max = count($max_key);
foreach($a as $i => $v) {
    if ($cnt_max === 1 && in_array($i, $max_key)) {
        echo($max2.PHP_EOL);
    } else {
        echo($max.PHP_EOL);
    }
}
?>