/*
TASK:names
LANG:C++
*/

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

char buf[2000010];
char best[2000010];
char temp[2000010];
char pre[2000010];
char mn[2000010];
char suf[2000010];
int len;

int main() {
    
    buf[0] = '\0';
    int i, j, k;
    
    while (true) {
        gets(buf);
        if (buf[0] == '\0') {
            break;
        }
        
        len = strlen(buf);
        strcpy(best, buf);
        
        for (i = 2; i < len; i++) {
            for (j = 1; j < i; j++) {
                for (k = 0; k < j; k++) {
                    pre[k] = buf[k];
                }
                pre[k] = '\0';
                for (k = 0; k < i-j; k++) {
                    mn[k] = buf[j+k];
                }
                mn[k] = '\0';
                for (k = 0; k < len - i; k++) {
                    suf[k] = buf[i+k];
                }
                suf[k] = '\0';
                strcpy(temp, mn);
                strcat(temp, pre);
                strcat(temp, suf);
                if (strcmp(temp, best) < 0) {
                    strcpy(best, temp);
                }
                strcpy(temp, mn);
                strcat(temp, suf);
                strcat(temp, pre);
                if (strcmp(temp, best) < 0) {
                    strcpy(best, temp);
                }
                strcpy(temp, suf);
                strcat(temp, pre);
                strcat(temp, mn);
                if (strcmp(temp, best) < 0) {
                    strcpy(best, temp);
                }
                strcpy(temp, pre);
                strcat(temp, suf);
                strcat(temp, mn);
                if (strcmp(temp, best) < 0) {
                    strcpy(best, temp);
                }
            }
        }
        printf("%s\n", best);
        buf[0] = '\0';
    }
    
    return 0;
}
