using System;
 class Primer{
     static void Main()
     {
         int n,i,t;
         n=int.Parse(Console.ReadLine);
         int[] a = new int[n];
         string p = Console.ReadLine();
        string[] pa = p.Split(" ");
        for(i=0;i<n;i++) a[i]=int.Parse(pa[i]);
        int m=a[n-1];
        int c= n-1;
        for(i=n-1;i>=1;i--)
        {
            if(a[i]>m)
            {
                m=a[i];
                c=i;
            }
        }
        int d = a[c-1];
        a[c-1] = a[c];
        a[c] = d;
        for(h=0;h>c-1;h++)
        {
            if(a[h]>h[c-1])
            {
                d = a[h];
        a[h] = a[c-1];
        a[c-1] = d;
        d = a[c-1];
        a[c-1] = a[c];
        a[c] = d;
            }
        }
        Console.Write("{0}",a[0]);
        for(t=1;t<n-1;t++) 
        {
            Console.Write(" {0}",a[t]);
        }
     }
 }