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

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            int[] a = new int[n];
            
            for (int i=0;i<n-1;i++)
            {
                int p = s.IndexOf(" ");
                a[i] = Convert.ToInt32(s.Substring(0, p));
                s = s.Remove(0, p+1);
            }
            a[n - 1] = Convert.ToInt32(s);
            int br = 0;
            if (n == 2)
            {
                int pom = a[0];
                a[0] = a[1];
                a[1] = pom;
            }
            else
            {
                int max = a[0];
                int max2 = a[1];
                int m1 = 0;
                for (int i=0;i<n;i++)
                {
                    max = a[i];
                    for (int j=i+1;j<n;j++)
                    {
                        if (max<a[j])
                        {
                            max = a[j];
                            m1 = j;
                        }
                        
                    }
                    if (max!=a[i])
                    {
                        int pom = a[i];
                        a[i] = a[m1];
                        a[m1] = pom;
                        br++;
                        break;
                    }
                    

                }
                if (br==0)
                {
                    int pom = a[0];
                    a[0] = a[1];
                    a[1] = pom;
                }
                
            }
            string x = "";
            for (int i=0;i<n;i++)
            {
                x += a[i].ToString() + " ";
            }
            Console.WriteLine(x);
            

        }
    }
}