function Main(input){

  var N = input.split('\n');
  var A = input.split('\n');
  var As = input.split('\n');
  N = parseInt(N,10);
  A.shift();
  As.shift()
  for(i=0;i<N;i++){
    A[i] = parseInt(A[i],10);
    As[i] = parseInt(As[i],10);
  }
  As.sort((a,b)=>{
    return b - a;
  });

  var maxF = As[0];
  var maxS = As[1];  


  A = A.map(x=>{
    if(x===maxF){
      return maxS;
    }else{
      return maxF;
    }
  });


  console.log(A.join('\n'));


}
  




Main(require("fs").readFileSync("/dev/stdin", "utf8"));