#include <bits/stdc++.h>

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define nul(x) memset((x),0,sizeof((x)))
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int n,k,d[10];
int a  [1000100];
int cnt[1000100];

void output(){
    for (int i=1;i<=n;i++)cout<<a[i]<<" ";
    exit(0);
}

int main() {
    ios;
    nul(d);
    nul(cnt);

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

    for (int i=1;i<=n;i++){
        for (int j=9;j>=a[i]+1;j--){
            if (d[j]>i){
                swap(a[i],a[d[j]]);
                output();
            }
        }
    }
    for (int i=0;i<=9;i++){
    	if (cnt[i]>1)output();
    }
    
    for (int i=n;i>=1;i--){
        for (int j=9;j>=0;j--){
            if (d[j]>i){
                swap(a[i],a[d[j]]);
                output();
            }
        }
    }
    swap(a[n],a[n-1]);
    output();
    return 0;
}