#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s;
cin >> s;
char minSymbol = 'Z';
vector <int> indicesOfMinSymbol;
for (int i = 0; i < s.size(); i++) {
if (s[i] < minSymbol)
minSymbol = s[i];
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == minSymbol && s[i - 1] != minSymbol)
indicesOfMinSymbol.push_back(i);
}
int indexOfMinLexicSubstr = indicesOfMinSymbol[0];
for (int i = 1; i < indicesOfMinSymbol.size(); i++) {
if (s.compare(indexOfMinLexicSubstr, s.size() - indicesOfMinSymbol[i], s, indicesOfMinSymbol[i], string::npos) > 0)
indexOfMinLexicSubstr = indicesOfMinSymbol[i];
}
rotate(s.begin(), s.begin() + indexOfMinLexicSubstr, s.end());
cout << s;
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglzdHJpbmcgczsKCWNpbiA+PiBzOwoJY2hhciBtaW5TeW1ib2wgPSAnWic7Cgl2ZWN0b3IgPGludD4gaW5kaWNlc09mTWluU3ltYm9sOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBzLnNpemUoKTsgaSsrKSB7CgkJIGlmIChzW2ldIDwgbWluU3ltYm9sKSAKCQkgICAgbWluU3ltYm9sID0gc1tpXTsKCX0KCWZvciAoaW50IGkgPSAwOyBpIDwgcy5zaXplKCk7IGkrKykgewoJCSBpZiAoc1tpXSA9PSBtaW5TeW1ib2wgJiYgc1tpIC0gMV0gIT0gbWluU3ltYm9sKSAKCQkgICAgIGluZGljZXNPZk1pblN5bWJvbC5wdXNoX2JhY2soaSk7Cgl9CglpbnQgaW5kZXhPZk1pbkxleGljU3Vic3RyID0gaW5kaWNlc09mTWluU3ltYm9sWzBdOwoJZm9yIChpbnQgaSA9IDE7IGkgPCBp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