#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int maxIndex(int a[], int n, int start = 0) {
    int maxi = a[start];
    int index = start;
    for (int i = start; i < n; i++) {
        if (a[i] > maxi) {
            maxi = a[i];
            index = i;
        }
    }

    return index;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];

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

    // worst case O(n^2), might give like 60-70pts idk maybe like who cares this shit is for cia nigger faggots

    int t;

    for (int i = 0; i < n - 1; i++) {
        int index = maxIndex(a, n, i + 1);

        if (a[index] >= a[i]) {
            t = a[i];
            a[i] = a[index];
            a[index] = t;
            goto FINISH;
        }
    }

    // if already sorted, swap the last 2 digits

    t = a[n - 2];
    a[n - 2] = a[n - 1];
    a[n - 1] = t;

    FINISH:
        ;

    for (int i = 0; i < n; i++) {
        cout << a[i] << ' ';
    }

    return 0;
}