#include <iostream>
#include <stdio.h>

using namespace std;

void Uradi(int a[], unsigned long n, int maximum, unsigned long k)
{
    unsigned long i,maxi=0,maxii=0,mini=9,minii=0;
    int ok=0;
    for (i=k; i<n; i++)
    {
        if ((a[i]>=maxi) && (a[i]<=maximum))
        {
            maxi=a[i];
            maxii=i;
        }
        if (a[i]<mini)
        {
            mini=a[i];
            minii=i;
        }
    }
    i=k;
    if (maxii!=0)
    {
        while ((i<maxii) || (ok==0))
        {
            if (a[i]<maxi)
            {
                a[maxii]=a[i];
                a[i]=maxi;
                maxii=i;
                ok=1;
            }
            i++;
        }
    }
    if (ok==0)
    {
        if (maxi!=mini)
        {
            Uradi(a,n,maximum-1,maxii+1);
        }
    }
    else
    {
        for (i=0; i<n; i++)
        {
            printf("%d",a[i]);
            if (i<n-1)
                printf(" ");
        }
    }
}
int main()
{
    unsigned long n,i;
    int ok=0;
    scanf("%lu",&n);
    int a[n];
    for (i=0; i<n; i++)
        scanf("%d",&a[i]);
    if (n==2)
            printf("%lu %lu",a[1],a[0]);
    else
        Uradi(a,n,9,0);
    return 0;
}