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

namespace ConsoleApplication29
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            var ulaz = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(ulaz[i]);
            }
            if (n == 2)
            {
                Console.Write(a[1] + " ");
                Console.WriteLine(a[0]);
                return;
            }
            int imaks = 0;
            int maks = 0;
            for (int i = 1; i < n; i++)
            {
                maks = Math.Max(a[i - 1], a[i]);
                if (a[i] == maks)
                {
                    imaks = i;
                }
            }
            int p = a[0];
            a[0] = a[imaks];
            a[imaks] = p;
            for (int i = 0; i < n; i++)
            {
                Console.Write(a[i] + " ");
            }
        }
    }
}