using System;

namespace Polica
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Unesi broj knjiga (N >= 2): ");
            int N = int.Parse(Console.ReadLine());
            if (N >= 2)
            {
                int br = 0;
                int[] A = new int[N];
                for (int i = 0; i < N; i++)
                {
                    A[i] = int.Parse(Console.ReadLine());
                    if (A[i] > 9 || br == 2 || A[i] < 0)
                    {
                        break;
                    }
                    if (A[i] == 0)
                    {
                        br++;
                    }
                }
                double max = 0;
                int j = 0;
                for (int i = N - 1; i >= 0; i--)
                {
                    max += A[j++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(i));
                }
                int pom;
                double nb = 0;
                if (N > 2)
                {
                    for (int i = 0; i < N - 1; i++)
                    {
                        for (j = i + 1; j < N; j++)
                        {
                            nb = 0;
                            pom = A[i];
                            A[i] = A[j];
                            A[j] = pom;
                            int m = 0;
                            for (int k = N - 1; k >= 0; k--)
                            {
                                nb += A[m++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(k));
                            }
                            pom = A[j];
                            A[j] = A[i];
                            A[i] = pom;
                            if (nb > max)
                            {
                                max = nb;
                            }
                        }
                    }
                }
                if (N == 2)
                {
                    pom = A[0];
                    A[0] = A[1];
                    A[1] = pom;
                    int m = 0;
                    for (int k = N - 1; k >= 0; k--)
                    {
                        nb += A[m++] * Math.Pow(Convert.ToDouble(10), Convert.ToDouble(k));
                    }
                    max = nb;
                }
                Console.WriteLine(max);
            }
        }
    }
}