"use strict";
const input = require("fs").readFileSync("/dev/stdin", "utf8");
const inputs = input.trim().split("\n");

const get = (inputs) => {
  const As = inputs.slice(1);
  
  let max = 1;
  let max2 = 1;
  for (const A of As) {
    const a = +A;
    if (max < a) {
      max = a;
    } else if (max2 < a) {
      max2 = a;
    }
  }
  
  return As.map(A => +A === max ? max2 : max).join("\n")
}

console.log( get(inputs) );