#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,i,b,c=0;
    vector <int> v;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a;
        v.push_back(a);
    }
    int max1;
    for(i=0;i<n;n--)
    {
         max1=*max_element(v.begin(),v.end());
        if(max1==v[i])
        {

            if (v.size()==2)
                break;
            cout << v[0] << " ";
            v.erase(v.begin());
        }
        else
        {
            c=1;
            for(i=v.size()-1;i>=0;i--)
            {
                if(v[i]==max1)
                {
                    b=v[i];
                    v[i]=v[0];
                    v[0]=b;
                    break;
                }
            }
            break;
        }
    }
    if(c==0)
    {
        b=v[v.size()-1];
        v[v.size()-1]=v[v.size()-2];
        v[v.size()-2]=b;
    }
    for(i=0;i<v.size();i++)
    {
        cout << v[i]<< " ";
    }
}