#include <iostream>
#include <cstring>
using namespace std;
const int MAX_LENGTH = 101;
int main() {
char s[MAX_LENGTH];
cin >> s;
char maxS[MAX_LENGTH];
strcpy(maxS, s);
int size = strlen(s);
int start = size - 1;
bool found = false;
for(int i = 0; i < size and !found; i++){
for(int j = i; j < size; j++){
if(s[j] > s[i]){
start = i;
found = true;
break;
}
}
}
for(int j = start + 1; j < size; j++){
if(s[j] >= s[start]) {
char curMax[MAX_LENGTH];
strcpy(curMax, s);
for (int k = j; k < size; k++) {
char temp = s[k];
for(int i = k; i > start + k - j; i--){
curMax[i] = curMax[i - 1];
}
curMax[start + k - j] = temp;
if(strncmp(curMax, maxS, size) > 0){
strcpy(maxS, curMax);
}
}
}
}
cout << maxS;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYX0xFTkdUSCA9IDEwMTsKCmludCBtYWluKCkgewogICAgY2hhciBzW01BWF9MRU5HVEhdOwogICAgY2luID4+IHM7CiAgICBjaGFyIG1heFNbTUFYX0xFTkdUSF07CiAgICBzdHJjcHkobWF4Uywgcyk7CiAgICBpbnQgc2l6ZSA9IHN0cmxlbihzKTsKICAgIGludCBzdGFydCA9IHNpemUgLSAxOwogICAgYm9vbCBmb3VuZCA9IGZhbHNlOwogICAgZm9yKGludCBpID0gMDsgaSA8IHNpemUgYW5kICFmb3VuZDsgaSsrKXsKICAgICAgICBmb3IoaW50IGogPSBpOyBqIDwgc2l6ZTsgaisrKXsKICAgICAgICAgICAgaWYoc1tqXSA+IHNbaV0pewogICAgICAgICAgICAgICAgc3RhcnQgPSBpOwogICAgICAgICAgICAgICAgZm91bmQgPSB0cnVlOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGogPSBzdGFydCArIDE7IGogPCBzaXplOyBqKyspewogICAgICAgIGlmKHNbal0gPj0gc1tzdGFydF0pIHsKICAgICAgICAgICAgY2hhciBjdXJNYXhbTUFYX0xFTkdUSF07CiAgICAgICAgICAgIHN0cmNweShjdXJNYXgsIHMpOwogICAgICAgICAgICBmb3IgKGludCBrID0gajsgayA8IHNpemU7IGsrKykgewogICAgICAgICAgICAgICAgY2hhciB0ZW1wID0gc1trXTsKICAgICAgICAgICAgICAgIGZvcihpbnQgaSA9IGs7IGkgPiAgc3RhcnQgKyBrIC0gajsgaS0tKXsKICAgICAgICAgICAgICAgICAgICBjdXJNYXhbaV0gPSBjdXJNYXhbaSAtIDFdOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY3VyTWF4W3N0YXJ0ICsgayAtIGpdID0gdGVtcDsKICAgICAgICAgICAgICAgIGlmKHN0cm5jbXAoY3VyTWF4LCBtYXhTLCBzaXplKSA+IDApewogICAgICAgICAgICAgICAgICAgIHN0cmNweShtYXhTLCBjdXJNYXgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBtYXhTOwogICAgcmV0dXJuIDA7Cn0=