using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class350
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var 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)
                {
                    var B = new int[N];
                    Array.Copy(A, B, N);
                    B[i] = -1;
                    Console.WriteLine(B.Max());
                }
                else
                {
                    Console.WriteLine(max);
                }
            }
        }
    }
}
