<?php
  
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}
#$v2 = str_split($stdin[0]);
#$v2 = explode(" ", $stdin[0]);

#var_dump($stdin);

unset($stdin[0]);

$max = max($stdin);

$array2 = $stdin;
arsort($array2);


$array2 = array_values(array_unique($array2));

#var_dump($stdin);
#var_dump($array2);

$ans = NULL;

foreach($stdin as $k => $v){
  if($v == $max){
    if(!isset($array2[1])){
      $ans .= $max . PHP_EOL;
    }else{
      $ans .= $array2[1] . PHP_EOL;
    }
  }else{
    $ans .= $max . PHP_EOL;
  }
}





echo $ans . PHP_EOL;