#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    int x = 0;
    int m = 0;
    int mesto = 0;
    bool vece = true;

    for(int ia = 1; ia<=n; ia++){
        cin>>a[ia];
    }

    for(int i = 1; i <= n; i++){
        m = 0;
        if(vece == false){
            //cout<<"vece je false"<<endl;
            break;
        }

        for(int j = i; j <= n; j++){
            //cout<<"usao for j"<<endl;
            if(m <= a[j]){
                m = a[j];
                mesto = j;
            }
        }

            if( a[i] < m ){
                vece = false;
                x = a[i];
                a[i] = m;
                m = x;
                a[mesto]=m;
                //cout<<"Usao if a<a i a[i] "<<a[i]<<"a[j]"<<a[j]<<"gde su i i j"<<i<<j<<"vece je"<<vece<<endl;
                break;
            }

    }
    if(vece == true){
        x = a[n-1];
        a[n-1] = a[n];
        a[n] = x;
    }
    for(int pr=1;pr<=n;pr++){
        cout<<a[pr]<<" ";
    }
}