function main(input){
  input = input.split("\n");
  var n = parseInt(input[0]);

  var a = [];

  for (var i = 0; i < n; i++) {
    a[i] = {
      index : i,
      num : parseInt(input[i+1])
    };
  }

  a.sort(function(a,b){
    if(a.num>b.num) return -1;
    if(a.num<b.num) return 1;
    return 0;
  })

  max_index = a[0].index;
  max_num = a[0].num;

  for (var i = 0; i < n; i++) {
    if (i !== max_index) {
      console.log(max_num);
    }else {
      console.log(a[1].num);
    }
  }


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