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

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <functional>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <complex>
#include <cctype>
#include <sstream>
#include <string>
using namespace std;

typedef complex<double> Point;
typedef complex<double> Vector;
typedef pair<int,int> pii;
typedef set<int> si;
typedef vector<int> vi;
typedef vector<string> vs;

#define rep(i, n) for( __typeof(n) i=0; i<n; i++ )
#define f(i, a, b) for( __typeof(a) i=a; i<b; i++ )
#define sz size()
#define pb push_back
#define all(v) v.begin(), v.end()
#define wait system("pause")
#define print(v, type, div) copy(all(v), ostream_iterator<type>(cout, div) ); wait



string s;
string min_s;
string temp;
char min_l;
int f_pos;
int s_pos;
int pos[200];
int pos1[200];
int n;
int n1;
int st;


inline void Before()
{
       temp="";
       
       f(j, st+1, s.sz)
       {
            if( s[j] > s[0] )
            {
                temp = s.substr(st, j-st) ;
                
                temp += s.substr(0, st);
                
                temp += s.substr(j);
                
                return;
            }
       }
       
       if( temp=="" )
       {
           temp=s.substr(st);
           
           temp+=s.substr(0, st);
       }
}

inline void Find_String()
{
       n=0;
       min_l='z';
       min_s="z";
       
       rep( i, s.sz )
       {
//            cout<< int(min_l) <<"  "<< int(s[i]) <<"\n";
//            wait;
            
            if( int(min_l) > int(s[i]) ) min_l = s[i];
       }
       
       rep( i, s.sz )
            if( min_l == s[i] ) pos[n++]=i;
       
       rep( i, n )
       {
            st=pos[i];
            
            if( st != 0 )
            {
                Before();
                
                if( min_s > temp ) min_s=temp;
            }
            else
            {
                temp="";
                min_l='z';
                n1=0;
                
                f(j, 1, s.sz)
                     if( (int)min_l > (int)s[j] )
                     {
                         min_l=s[j];
                         f_pos=j;
                     }
                
                min_l='z';
                
                f(j, 1, s.sz)
                     if( (int)min_l > (int)s[j] && j!=f_pos )
                     {
                         min_l=s[j];
                         s_pos=j;
                     }
                
                f(j, 1, s.sz)
                     if( (int)min_l == (int)s[j] ) pos1[n1++]=j;
                

                rep(j, n1)
                {
                       temp=s[0];
                       
                       temp+=s.substr(pos1[j]);
                       
                       temp+=s.substr(1, pos1[j]-1);
                       
                       
                       if( min_s > temp ) min_s=temp;
                }
            }
       }
}

void Solve()
{
     while( cin>>s )
     {
            Find_String();
            
            cout<< min_s <<"\n";
     }
}


int main()
{
    Solve();
    
    
//    wait;
    
    return 0;
}
