"use strict";
const main = arg => {
  let A = arg.split("\n").map(n=>n*1);
  let N = A[0];
  A = A.slice(1, N+1);
  let AA = arg.split("\n").map(n=>n*1).slice(1, N+1);
  let sortNum = AA.sort((a,b)=> {return b - a })
  let max = sortNum[0];
  let secondMax = sortNum[1];
  for(let i = 0; i < N; i++){
	if(max != A[i]){
      console.log(max)
    }else{
      console.log(secondMax);
    };
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
