#include <bits/stdc++.h>
using namespace std;

int a[1000007];
int c[10];
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    bool weHaveDuplicates = false;
    int n;
    cin >> n;

    for (int i = 0; i < 10; i++)
        c[i] = -1;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (c[a[i]] == -1)
            c[a[i]] = i;
        else {
            weHaveDuplicates = true;
            c[a[i]] = i;
        }
    }


    for (int i = 0; i < n; i++)  {
        for (int j = 9; j > a[i]; j--)
            if (c[j] != -1 && i < c[j]) {
                swap (a[c[j]], a[i]);
                for (int k = 0; k < n; k++)
                    cout << a[k] << " ";
                return 0;
            }
    }
    if (!weHaveDuplicates)
        swap(a[n-1], a[n-2]);
    for (int k = 0; k < n; k++)
        cout << a[k] << " ";
    return 0;
}