function Main(input) {
  var input = input.split("\n");
  input.shift();
  
  var max = 0;
  var next = 0;
  for (var i=0; i<input.length; i++) {
    if (max < input[i]) {
      next = max;
      max = input[i];
    } else if (next < input[i]) {
      next = input[i];
    }
  }
  for (var i=0; i<input.length; i++) {
    if (input[i] == max) {
      console.log(next);
    } else {
      console.log(max);
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));