function Main(input) {
  input = input.trim()
  input = input.split("\n");
  input.shift()
  var max=0;
  var submax=0
  var maxpoint = [];
  var list = input
  list.sort();
  max=list[list.length-1];
  submax=list[list.length-2];
  for(var j=0;j<input.length;j++){
    if(max==input[j]){
      maxpoint.push(j);
    }
  }
  for(var k=0;k<input.length;k++){
  	if(maxpoint.some(item => item === k+1)){
      	console.log(submax)
    }else{
      console.log(max)
    }
  }
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));