using System;
using System.Collections.Generic;
using System.Text;

namespace ABC134
{
    class Program3
    {
        static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var N = int.Parse(Console.ReadLine());
            var max1 = 0;
            var index1 = 0;
            var max2 = 0;
            var index2 = 0;
            for (int i = 0; i < N; i++)
            {
                var num = int.Parse(Console.ReadLine());
                if (num > max1)
                {
                    max1 = num;
                    index1 = i;
                }
                else if (num == max1 || num > max2)
                {
                    max2 = num;
                    index2 = i;
                }
            }

            for (int i = 0; i < N; i++)
                Console.WriteLine(i != index1 ? max1 : max2);
            Console.Out.Flush();
        }
    }
}
