function Main(input){
  inputs=input.split("\n");
  numbers=inputs.filter((x,i)=>i!==0&&x!="").map(x=>parseInt(x));

  count=parseInt(inputs[0]);
  countArray=[...Array(count)];

  max1=numbers.reduce((a,b,i)=>(b>a&&i<count)?b:a);
  max2=numbers.reduce((a,b,i)=>(b>a&&i<count&&(b<max1||b==a))?b:a);

  countArray.map((_,i)=>{
    console.log(numbers[i]!=max1?max1:max2);
  });
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));
