function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  var A = [];
  var fst = 2;
  var snd = 1;
  var now = 0;
  //パラメータを配列に確保しつつ最大値と２番目の値を変数に格納
  for( i=0 ; i<N ; i++ ){
    inputStr = input[i+1].split(" ");
    now = Number.parseInt(inputStr[0]);
    A.push(now);
    if( fst <= now ){
      snd = fst;
      fst = now;
    } else if( snd <= now ){
      snd = now;
    }
  }
  //結果表示
  for( j = 0 ; j < N ; j++){
    if(A[j]===fst){
      console.log(snd);
    } else {
      console.log(fst);
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));