#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (int)(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

int n, K;
string S;

inline void up(string &x, string y) {
	if (x.length() == 0 || x > y) x = y;
}

inline string rev(string str) {
	reverse(str.begin(), str.end());
	return str;
}

inline string split(string &t, int l, int r, bool f) {
	string ans = t.substr(l, r - l);
	if (f) ans = rev(ans);
	return ans;
}

int main(void) {
	cin >> n >> K;
	cin >> S;
	while (true) {
		string T = rev(S);
		string U = S + T;
		string ans = "";
		for (int i = 0; i <= n; i++) {
			up(ans, split(U, i, i + n, K == 1));
		}
		if (K > 1) ans = rev(ans);
		int ok = 1;
		for (int i = 1; i < n; i++)
			if (ans[i] != ans[0]) ok = 0;
		if (K == 1 || ok) {
			cout << ans << "\n";
			return 0;
		}
		S = ans;
		--K;
	}
}
