#include <bits/stdc++.h>

using namespace std;
bool funkcija2(int i,int j) { return (i > j);}

int main(){
    long long n;
    vector<char> b;
    vector<char> c;
    cin >> n;
    char a[n];
    int maxx = 0;
    int maxk, k = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];

    }



       b.assign(a, a+n);
       sort(b.begin(),b.end(), funkcija2);



       for(int i = 0; i < n;i++){
          if(a[i] != b[i]){
                k++;
            for(int j = n-1; j >= 0;j--){
               if(a[j] == b[i]){
                  maxk = j;
                  break;
               }
            }

            swap(a[i], a[maxk]);
            break;

          }





       }

    for(int i = 0;i < n;i++)
    {
        if(b[i] == b[i+1])
            k++;

    }



if(k == 0)
{

    swap(a[n-2], a[n-1]);



}


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

    }









    return 0;
}