#include <bits/stdc++.h>

using namespace std;

int r[1000000];

int main()
{
    int n, m = 0, mind;
    cin >> n;
    cin >> r[0];
    for(int i = 1; i < n; i++){
        cin >> r[i];
        if(r[i] > r[i-1] && r[i] >= m){
            mind = i;
            m = r[i];
        }
    }
    if(m){
        int i = 0;
        while(r[i] > m)i++;
        swap(r[i], r[mind]);
    }else if(n < 11){
        set<int> setic;
        int i = 0;
        while(!setic.count(r[i]) && i < n-1){
                setic.insert(r[i]);
                i++;
        }
        if(i == n-1)swap(r[n-2], r[n-1]);
    }
    for(int i = 0; i < n; i++)cout << r[i] << " ";
    return 0;
}