#include <iostream>

using namespace std;

int main()
{
    int n,x=0,y=0,k=0,m=0;
    cin>>n;
    int a[n];
    int b[n],c[n],d[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        c[i]=a[i];
    }
    for (int i=0;i<n-1;i++)
    {
        for (int j=i+1;j<n;j++)
        {
            if (a[i]<a[j])
                swap(a[j],a[i]);
        }
    }
    if (n==2)
    {
        swap(b[0],b[1]);
        for (int i=0;i<n;i++)
            cout<<b[i]<<" ";
        return 0;
    }
    if (a==b)
    {
        for (int i=0;i<n;i++)
            cout<<a[i]<<" ";
    }
    for (int i=0;i<n;i++)
    {
        if (a[i]>b[i])
            x=a[i];
            y=b[i];
            b[i]=x;
        break;
    }
    for (int i=0;i<n;i++)
    {
        if (c[i]==x)
            k=i;
    }
    b[k]=y;
    for (int i=0;i<n;i++)
    {
        cout<<b[i]<<" ";
    }
    return 0;
}