export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = parseInt(tmp[0].split(" ")[0]);
    const list: number[] = [];
    let max1: number = 0;
    let max2: number = 0;
    for (let i = 1; i <= n; i++) {
      const a: number = parseInt(tmp[i].split(" ")[0]);
      list.push(a);
      if (max1 < a) {
        if (max2 < max1) {
          max2 = max1;
        }
        max1 = a;
      } else if (max2 < a || max1 == a) {
        max2 = a;
      }
    }
    const m: number = Math.max(...list);
    const isMaxDouble: boolean = max1 == max2;
    const result: number[] = [];
    for (let i = 0; i < n; i++) {
      if (!isMaxDouble && list[i] == m) {
        result.push(max2);
      } else {
        result.push(max1);
      }
    }
    return `${result.join("\n")}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));