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

int main()
{
    int n;
    cin >> n;

    if (n == 2) {
        int a, b;
        cin >> a >> b;
        cout << b << " " << a;
        return 0;
    }

    char books[n];
    char cypher[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};

    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;

        books[i] = a;
        cypher[a] = i;
    }

    for (int i = 9; i; i--)
        if (cypher[i] > (-1))
            for (int j = 0; j < n; j++)
                if (books[j] < i && cypher[i] > j) {
                    books[j] ^= books[cypher[i]];
                    books[cypher[i]] ^= books[j];
                    books[j] ^= books[cypher[i]];

                    for (int z = 0; z < n; z++)
                        cout << char('0' + books[z]) << " ";

                    return 0;
                }

    books[0] ^= books[1];
    books[1] ^= books[0];
    books[0] ^= books[1];

    for (int i = 0; i < n; i++)
        cout << char('0' + books[i]) << " ";
}