function Main(input) {
  var input1 = input.split("\n");
  input1.shift();
  
  var input2 = input.split("\n");
  input2.shift();
  input2.sort(function(a, b){ return b-a; });
  
  for (var i=0; i<input1.length; i++) {
    if (input1[i] == input2[0]) {
      console.log('%d', input2[1]);
    } else {
      console.log('%d', input2[0]);
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));