#include <iostream>
#include <vector>

using namespace std;

int des[10];

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        des[a[i]] = i+1;
    }
    for (int i = 0; i < n; ++i){
        int maxf = 0;
        for (int j = a[i]+1; j < 10; ++j)
            if (des[j] != 0 && des[j] - 1 > i)
                maxf = des[j];
        if (maxf != 0){
            swap(a[i], a[maxf-1]);
            break;
        }
        if (i == n-1){
            bool p = false;
            for (int j = 0; j < n-1; ++j){
                if (a[j] == a[j+1]){
                    p = true;
                    break;
                }
            }
            if (!p)
                swap(a[i], a[i-1]);
        }
    }
    for (int i = 0; i < n; ++i)
        cout << a[i] << " ";
    return 0;
}