#include <iostream>
using namespace std;
class Solution {
public:
    string orderlyQueue(string S, int K) {
        if(K == 1){
            string ret = S;
            for(int len = 1; len  < S.size(); len ++){
                string t_ret = S.substr(len) + S.substr(0, len);
                if(t_ret < ret)
                    ret = t_ret;
            }
            return ret;
        }
        sort(S.begin(), S.end());
        return S;
    }
};
int main() {
    return 0;
}