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

namespace zadatak_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 n = int.Parse(Console.ReadLine());
            Int64[] a = new Int64[n];
            Int64 c = 0;
            Int64 d = 0;
            Int64 s = 0;
            var ulazna_linija = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i]= int.Parse(ulazna_linija[i]);
            }
            Int64 max = -999999999999999999;
            if (n == 2)
            {
                Console.Write(a[1]);
                Console.Write(" ");
                Console.WriteLine(a[0]);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    for (int k = i+1; k < n; k++)
                    {
                        c = a[i];
                        d = a[k];
                        a[i] = d;
                        a[k] = c;
                        s = 0;
                        for (int l = 0; l < n; l++)
                        {
                            s = s * 10 + a[l];
                        }
                        if (s > max)
                        {
                            max = s;
                            a[i] = c;
                            a[k] = d;
                        }
                        else
                        {
                            a[i] = c;
                            a[k] = d;
                        }

                    }


                }


                int u = 0;
                Int64 y = max;
                s = 0;
                while (y != 0)
                {

                    s = s * 10 + y % 10;
                    y /= 10;
                    u++;
                }
                for (int i = 0; i < n; i++)
                {
                    Console.Write(s % 10);
                    s /= 10;
                    if (i == n - 1)
                    {
                        Console.WriteLine(" ");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }

            }
        }
    }
}