using System;
using System.Linq;
class Program {
    static void Main (string[] args) {
        // 整数の入力
        int N = int.Parse (Console.ReadLine ());
        int[] numbers = new int[N];
        for (int i = 0; i < N; i++) {
            numbers[i] = int.Parse (Console.ReadLine ());
        }
        int max1 = numbers.Max ();
        for (int i = 0; i < N; i++) {
            if (numbers[i] == max1) {
                int tmp = numbers[i];
                numbers[i] = 0;
                Console.WriteLine (numbers.Max());
                numbers[i] = tmp;
            } else {
                Console.WriteLine (numbers.Max ());
            }
        }
    }
}