using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        int max = a.Max();
        for (int i = 0; i < n; i++)
        {
            if (a[i] == max)
            {
                a[i] = -1;
                Console.WriteLine(a.Max());
                a[i] = max;
            }
            else
                Console.WriteLine(max);
        }
    }
}