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

namespace Welcome_to_AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var array = new int[n];
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
            }

            int currentMaxValue = 0;
            for (int i = 0; i < array.Length; i++)
            {
                int max = 0;
                for (int j = i + 1; j < array.Length; j++)
                {
                    if (array.Length == j) break;

                    var value = array[j];
                    if (max > value)
                    {
                        max = value;
                    }
                }

                Console.WriteLine(new int[2] { currentMaxValue, max }.Max());

                var currentValue = array[i];
                if (currentValue > currentMaxValue)
                {
                    currentMaxValue = currentValue;
                }
            }
        }
    }
}
