#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	for(int i=1; i<K; ++i){
	    string T=S;
	    reverse(S.begin(), S.end());
	    T += S;
	    reverse(T.begin(), T.end());
	    string now=T.substr(0, N);
	    for(int i=1; i<N; ++i) now=min(now, T.substr(i, N));
	    if(now==S){
	        S=now;
	        break;
	    }
	    S=now;
	    reverse(S.begin(), S.end());
	}
	string T=S;
	reverse(S.begin(), S.end());
	T += S;
	string now=T.substr(0, N);
	for(int i=1; i<N; ++i) now=min(now, T.substr(i, N));
	cout << now << endl;
	return 0;
}
