#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

vector<int> suffix_array(string S) {
	vector<int> arr(S.size() + 1, 0);
	for (int i = 0; i < S.size(); i++) arr[i] = (S[i] - 'a') + 1;

	for (int i = 0; i < 18; i++) {
		vector<tuple<int, int, int>> tup;
		for (int j = 0; j < S.size(); j++) {
			tup.push_back(make_tuple(arr[j], arr[min((int)S.size(), j + (1 << i))], j));
		}
		sort(tup.begin(), tup.end());
		int id = 0;
		for (int j = 0; j < tup.size(); j++) {
			arr[get<2>(tup[j])] = id + 1;
			if (j + 1 < tup.size() && make_pair(get<0>(tup[j]), get<1>(tup[j])) != make_pair(get<0>(tup[j + 1]), get<1>(tup[j + 1]))) id = j + 1;
		}
	}
	vector<int> ret; for (int i = 0; i < S.size(); i++) ret.push_back(arr[i]);
	return ret;
}

int N, K; string S;

int main() {
	cin >> N >> K >> S; K = min(K, 15);

	for (int i = 0; i < K; i++) {
		string V = S; reverse(V.begin(), V.end());
		string W = S + V;
		vector<int> J = suffix_array(W);

		int minx = (1 << 30), ind = 0;
		for (int j = 0; j <= N; j++) {
			if (minx > J[j]) { minx = J[j]; ind = j; }
		}
		if (i != K - 1) { ind = N - ind; }
		S = W.substr(ind, N);
	}
	cout << S << endl;
	return 0;
}