#include <iostream>
using namespace std;

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, m, mp;
    m = -1;
    char tmp;
    char *c = new char[n];

    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> c[i];
    }
    for(int i = n-1;i > 0;i--){
        if(c[i] > m){
            m = c[i];
            mp = i;
        }
    }


    if(n>2){
        for(int i = 0;i < n;i++){
            if(c[i] < m){
                tmp = c[i];
                c[i] = c[mp];
                c[mp] = tmp;
                break;
            }
        }
    } else {
        tmp = c[0];
        c[0] = c[1];
        c[1] = tmp;
    }

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