using System;

namespace Permutacije
{
    class Program
    {
        static int[] niz;
        static int n;
        static int max = -1;
        static int counter = 0;
        static string nizlol;
        static void permutacije(int k)
       
        {
            string a = "";
            
                for (int i = k; i < n; i++)
                {
                    int help = niz[i]; niz[i] = niz[k]; niz[k] = help;
                    if (i == 0)
                        permutacije(k + 1);
                    a = "";
                    for (int j = 0; j < n; j++)
                    {
                        a += niz[j];
                    }
                    if (int.Parse(a) > max || max == int.Parse(nizlol) ) max = int.Parse(a);
                
                    help = niz[i]; niz[i] = niz[k]; niz[k] = help;
                }
            
        }
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            niz = new int[n];
            string nizhelp = Console.ReadLine();
            nizlol = "";
            for (int i = 0; i < n; i++)
            {
                niz[i] = int.Parse(nizhelp.Split(' ')[i]);
                nizlol += nizhelp.Split(' ')[i];
            }

           permutacije(0);
            string help1 = "" +max;
            for (int i = 0; i < help1.Length; i++)
            {
                Console.Write(help1[i] + " ");
            }
            
            Console.Read();
        }
    }
}