using System;

namespace Polica
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, i, j, temp, x = 0, y = 1;
            N = int.Parse(Console.ReadLine());

            int[] polc = new int[N];
            string[] value = Console.ReadLine().Split(' ');
            for (i = 0; i < N; i++) polc[i] = int.Parse(value[i]);

            j = 0;
            temp = polc[j];
            if (N > 2)
            {
                for (i = 0; i < N; i++)
                {
                    temp = polc[i];
                    for (j = i + 1; j < N; j++)
                    {
                        if (polc[j] > temp)
                        {
                            temp = polc[j];
                            x = i;
                            y = j;
                            //Console.WriteLine(y);
                        }
                        if (j == N - 1 && temp > polc[i])
                        {
                            i = N-1;
                            break;
                        }
                    }
                    if (i == N - 2 && y== 1)
                    {
                        x = N - 2;
                        y = N - 1;
                    }
                }

            }

            temp = polc[x];
            polc[x] = polc[y];
            polc[y] = temp;

            for (i = 0; i < N; i++) Console.Write("{0} ", polc[i]);

            /*Console.WriteLine();
            Console.WriteLine("press any key");
            Console.ReadKey();*/

        }
    }
}