#include <iostream>
#include <cstdio>
#define MM 1000001
using namespace std;

int main()
{
    bool flag = 1;
    short unsigned int a[MM];
    long n, ind = -1;
    scanf("%ld", &n);
    scanf("%hu", &a[0]);
    for (long i = 1; i < n; i ++)
    {
        scanf("%hu", &a[i]);
        if(a[i - 1] >= a[i])
            continue;
        if(a[i] >= a[ind])
            ind = i;
    }
    if(ind < 0)
        for (long i = 0; i < n; i ++)
        {
            printf("%hu ", a[i]);
        }
    else
        for (long i = 0; i < n; i ++)
        {
            if(flag && a[ind] > a[i])
            {
                printf("%hu ", a[ind]);
                a[ind] = a[i];
                flag = 0;
            }
            else
                printf("%hu ", a[i]);
        }
    return 0;
}