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

namespace ConsoleApplication27
{
    class Program
    {
        static long lepota(long[] x,long n)
        {
            long s  = 0;
            double t = Math.Pow(10, n - 1);
            for (long i = 0; i < n; i++)
            {
                s = s + x[i] * Convert.ToInt64(t);
                t = t / 10;
            }
            return s;
        }
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] x = new long[n];
            long[] r = new long[n];
            long[] r1 = new long[n];
            string[] s = Console.ReadLine().Split(' ');
            double a = Math.Pow(10, n-1);
            long max = int.MinValue;
            long min = int.MaxValue;
            for (long i = 0; i < n; i++)
            {
                x[i] = Convert.ToInt64(s[i]);
            }
            long pocetna = lepota(x, n);
            for (long i = 0; i < n; i++)
            {
                for (long j = 0; j < n; j++)
                {
                    if (i != j)
                    {
                        long t = x[i];
                        x[i] = x[j];
                        x[j] = t;
                        long b = lepota(x, n);
                        
                        if (b >= pocetna&&b>max)
                        {
                            for (int l = 0; l < n; l++)
                            {
                                r[l] = x[l];
                            }
                            max = b;
                        }
                        else
                        {
                            if (pocetna-b < min)
                            {
                                for (int l = 0; l < n; l++)
                                {
                                    r1[l] = x[l];
                                }
                                min = pocetna - b;
                            }
                        }
                        long t1 = x[i];
                        x[i] = x[j];
                        x[j] = t1;
                    }
                }
                
            }
            string s1 = "";
            if (max < pocetna)
            {
                for (int i = 0; i < n; i++)
                {
                    s1 = s1 + Convert.ToString(r1[i]) + ' ';
                }
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    s1 = s1 + Convert.ToString(r[i]) + ' ';
                }
            }
            Console.WriteLine(s1);

            
            
        }
    }
}