#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
int n, k, i;
char c[10005], ans[10005], mn = 127;
struct str {
  char c[5005];
} p[5005];
bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; }
void dfs(char c[], int k) {
  int i, j, mx = 0, s[10005];
  memset(s, 0, sizeof(s));
  for (i = 1; i <= n; i++)
    if (c[i] != mn) break;
  if (i > n) {
    for (i = 1; i <= n; i++) printf("%c", mn);
    exit(0);
  }
  for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1];
  if (k == 1) {
    for (i = 1; i <= 2 * n;) {
      if (c[i] != mn) {
        i++;
        continue;
      }
      for (j = i; j <= 2 * n && c[i] == c[j]; j++)
        ;
      s[i] = j - i;
      i = j;
    }
    for (i = 1; i <= n; i++) mx = max(mx, s[i]);
    int u = 0;
    for (i = 1; i <= n; i++)
      if (mx == s[i]) {
        u++;
        for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j];
      }
    sort(p + 1, p + 1 + u, cmp);
    if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) < 0)
      for (i = 1; i <= n; i++) ans[i] = p[1].c[i];
    return;
  }
  char m[10005];
  for (i = n * 2; i >= 1;) {
    if (c[i] != mn) {
      i--;
      continue;
    }
    for (j = i; j >= 1 && c[i] == c[j]; j--)
      ;
    s[i] = i - j;
    i = j;
  }
  for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]);
  for (i = n; i < 2 * n; i++)
    if (mx == s[i]) {
      for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j];
      dfs(m, k - 1);
    }
}
int main() {
  scanf("%d %d", &n, &k);
  scanf("%s", c + 1);
  for (i = 1; i <= n; i++) mn = min(mn, c[i]);
  dfs(c, k);
  printf("%s", ans + 1);
}
