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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string nn = Console.ReadLine();
            int n = Convert.ToInt32(nn);
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int b = 0; b < n; b++)
                a[b] = Convert.ToInt32(s[b]);
            int br = 0,bri=0;
            int i=0;
            while(i<n && br==0)
            {
                int maks = a[i];
                for (int j = i; j < n; j++)
                {
                    if (a[j] > maks)
                    {
                        maks = a[j];
                        bri=j;
                    }
                }
                if(maks>a[i])
                {
                    a[bri] = a[i];
                    a[i] = maks;
                    br++;
                }
                i++;
            }
            if (br == 0)
            {
                i = 0;
                while (i < n && br == 0)
                {
                    int min = a[i];
                    for (int j = i; j < n; j++)
                    {
                        if (a[j] <min)
                        {
                            min = a[j];
                            bri = j;
                        }
                    }
                    if (min < a[i])
                    {
                        a[bri] = a[i];
                        a[i] = min;
                    }
                    i++;
                } 
            }
            for (int b = 0; b < n; b++)
                Console.Write(a[b] + " ");
            Console.ReadLine();
        }
    }
}