#include <iostream>
#include <vector>

using namespace std;
typedef long unsigned int lui;
int main()
{
    std::ios::sync_with_stdio(false);
    lui n;
    cin >> n;
    vector<lui> cifre;
    for (lui i = 0; i < n; i++) {
        unsigned int k;
        cin >> k;
        cifre.push_back(k);
    }
    bool found = false;
    unsigned int bignigga = 0;
    lui bignigga1 = n-2;
    lui bignigga2 = n-1;
    for (lui i = 0; i < n-1; i++) {
        for (lui k = i+1; k<n; k++) {
            if (cifre[i]==9) break;
            if (cifre[k] > cifre[i]) {
                    //cout << "yay" << endl;
                found = true;
                //cout << "cifre[k], bignigga: " << en
                if (cifre[k] >= bignigga) {
                    //cout << "big yay" << endl;
                    bignigga = cifre[k];
                    bignigga2 = k;
                    bignigga1 = i;
                }
            }
        }
        if (found) break;
    }
    //cout << "FOUND!!" << endl;
    //cout << "biggnigga1,2: " << bignigga1 << " " << bignigga2 << endl;
        unsigned int u = cifre[bignigga1];
        cifre[bignigga1] = cifre[bignigga2];
        cifre[bignigga2] = u;
    for (lui i = 0; i <n; i++) cout << cifre[i] << " ";

    return 0;
}