#include<bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define NL(x) " \n"[(x)]
#define lld long long
#define pil pair<int,lld>
#define pli pair<lld,int>
#define pll pair<lld,lld>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1000010
int cnt[10], c[MAXN];

int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    int N; cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> c[i];
        cnt[c[i]]++;
    }
    int cif = 9;
    for(int i = 1; i <= N; i++) {
        while(cnt[cif] == 0) cif--;
        if(c[i] == cif) cnt[cif]--;
        else {
            for(int j = N; j > i; j--) {
                if(c[j] == cif) {
                    swap(c[i], c[j]);
                    goto ispis;
                }
            }
        }
    }
    swap(c[N-1], c[N]);
    ispis:
    for(int i = 1; i <= N; i++) cout << c[i] << ' ';
    return 0;
}