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

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] st = Console.ReadLine().Split();
            
            int indeks = 0;

            if (n == 2)
            {
                Console.WriteLine(st[1] + " " + st[0]);
            }
            else
            {
                int max = int.MinValue;
                for (int i = 1; i < n; i++)
                {
                    if (max < Convert.ToInt32(st[i]))
                    {
                        max = Convert.ToInt32(st[i]);
                        indeks = i;
                    }                    
                }
                
                for (int i = 0; i < n; i++)
                {
                    if (Convert.ToInt32(st[i]) <= max)
                    {
                        st[indeks] = st[i];
                        st[i] = Convert.ToString(max);
                        break;
                    }
                }
                for (int i = 0; i < n; i++)
                {
                    if (i == n - 1)
                        Console.Write(st[i]);
                    else
                    Console.Write(st[i] + " ");
                }
            }           
        }
    }
}