#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
string s;
int n, k;
string process(string s) {
  if (k == 1) return s;
  int l;
  for (l = 1; l <= n && s[n - l] == s.back(); l++)
    ;
  l--;
  long long p;
  if (k - 2 >= 30)
    p = n;
  else
    p = min((1 << (k - 2)) * l, n);
  string t;
  if (k != 2) {
    for (int i = p; i < n - 1; i++) t += s[i];
    for (int i = 0; i < p; i++) t += s.back();
  } else
    t = s;
  string rev_t = t;
  reverse(rev_t.begin(), rev_t.end());
  string tt = t + rev_t, ans;
  for (int i = n - p; i < 2 * n - p; i++) ans += tt[i];
  return ans;
}
int main() {
  cin >> n >> k;
  cin >> s;
  string best = s;
  string rev_s = s;
  reverse(rev_s.begin(), rev_s.end());
  s = s + rev_s;
  for (int i = 0; i < s.size() / 2; i++)
    best = min(process(s.substr(i, s.size() / 2)), best);
  cout << best;
}
