using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AtCoder_Beginner_Contest_134
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static  void Solve()
        {
            var N = Sarray()[0];
            var Ai = new long[N];
            for (var i = 0; i < N; ++i)
            {
                Ai[i] = Sarray()[0];
            }
            var max = new long[N];
            var revmax = new long[N];
            max[0] = Ai[0];
            revmax[0] = Ai[N - 1];
            for (var i = 1; i < N; ++i)
            {
                max[i] = Math.Max(max[i - 1], Ai[i]);
                revmax[i] = Math.Max(max[i - 1], Ai[N - 1 - i]);
            }
            WriteLine(revmax[N - 2]);
            for (var i = 0; i < N - 2; ++i)
            {
                WriteLine(Math.Max(max[i], revmax[N - 3 - i]));
            }
            WriteLine(max[N - 2]);
        }
    }
}
