#include <iostream>

using namespace std;

int main()
{
    int broj1=0,broj2=0,index=0;
    long n;
    cin>>n;
    int niz1[n];
    int niz2[n],niz3[n];
    for (int i=0;i<n;i++)
    {
        cin>>niz1[i];
        niz2[i]=niz1[i];
        niz3[i]=niz1[i];
    }
    for (int i=0;i<n-1;i++)
    {
        for (int j=i+1;j<n;j++)
        {
            if (niz1[j]>niz1[i])
                swap(niz1[j],niz1[i]);
        }
    }
    if (n==2)
    {
        swap(niz2[0],niz2[1]);
        for (int i=0;i<n;i++)
            cout<<niz2[i]<<" ";
        return 0;
    }
    if (niz1==niz2)
    {
        for (int i=0;i<n;i++)
            cout<<niz1[i]<<" ";
    }
    for (int i=0;i<n;i++)
    {
        if (niz2[i]<niz1[i])
            broj1=niz1[i];
            broj2=niz2[i];
            niz2[i]=broj1;
        break;
    }
    for (int i=0;i<n;i++)
    {
        if (niz3[i]==broj1)
            index=i;
    }
    niz2[index]=broj2;
    for (int i=0;i<n;i++)
    {
        cout<<niz2[i]<<" ";
    }
    return 0;
}