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