#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T &a, const T &val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T &a, const T &val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int &a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int &a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() { return abs((int)mt()); }
unsigned char mask[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
void getBuckets(unsigned char *s, int *bkt, int n, int K, int cs, bool end) {
  int i, sum = 0;
  for (i = 0; i <= K; i++) bkt[i] = 0;
  for (i = 0; i < n; i++)
    bkt[(cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i])]++;
  for (i = 0; i <= K; i++) {
    sum += bkt[i];
    bkt[i] = end ? sum : sum - bkt[i];
  }
}
void induceSAl(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n,
               int K, int cs, bool end) {
  int i, j;
  getBuckets(s, bkt, n, K, cs, end);
  for (i = 0; i < n; i++) {
    j = SA[i] - 1;
    if (j >= 0 && !((t[(j) / 8] & mask[(j) % 8]) ? 1 : 0))
      SA[bkt[(cs == sizeof(int) ? ((int *)s)[j] : ((unsigned char *)s)[j])]++] =
          j;
  }
}
void induceSAs(unsigned char *t, int *SA, unsigned char *s, int *bkt, int n,
               int K, int cs, bool end) {
  int i, j;
  getBuckets(s, bkt, n, K, cs, end);
  for (i = n - 1; i >= 0; i--) {
    j = SA[i] - 1;
    if (j >= 0 && ((t[(j) / 8] & mask[(j) % 8]) ? 1 : 0))
      SA[--bkt[(cs == sizeof(int) ? ((int *)s)[j] : ((unsigned char *)s)[j])]] =
          j;
  }
}
void SA_IS(unsigned char *s, int *SA, int n, int K, int cs) {
  int i, j;
  unsigned char *t = (unsigned char *)malloc(n / 8 + 1);
  t[(n - 2) / 8] = (0) ? (mask[(n - 2) % 8] | t[(n - 2) / 8])
                       : ((~mask[(n - 2) % 8]) & t[(n - 2) / 8]);
  t[(n - 1) / 8] = (1) ? (mask[(n - 1) % 8] | t[(n - 1) / 8])
                       : ((~mask[(n - 1) % 8]) & t[(n - 1) / 8]);
  for (i = n - 3; i >= 0; i--)
    t[(i) / 8] =
        (((cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i]) <
              (cs == sizeof(int) ? ((int *)s)[i + 1]
                                 : ((unsigned char *)s)[i + 1]) ||
          ((cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i]) ==
               (cs == sizeof(int) ? ((int *)s)[i + 1]
                                  : ((unsigned char *)s)[i + 1]) &&
           ((t[(i + 1) / 8] & mask[(i + 1) % 8]) ? 1 : 0) == 1))
             ? 1
             : 0)
            ? (mask[(i) % 8] | t[(i) / 8])
            : ((~mask[(i) % 8]) & t[(i) / 8]);
  int *bkt = (int *)malloc(sizeof(int) * (K + 1));
  getBuckets(s, bkt, n, K, cs, true);
  for (i = 0; i < n; i++) SA[i] = -1;
  for (i = 1; i < n; i++)
    if ((i > 0 && ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0) &&
         !((t[(i - 1) / 8] & mask[(i - 1) % 8]) ? 1 : 0)))
      SA[--bkt[(cs == sizeof(int) ? ((int *)s)[i] : ((unsigned char *)s)[i])]] =
          i;
  induceSAl(t, SA, s, bkt, n, K, cs, false);
  induceSAs(t, SA, s, bkt, n, K, cs, true);
  free(bkt);
  int n1 = 0;
  for (i = 0; i < n; i++)
    if ((SA[i] > 0 && ((t[(SA[i]) / 8] & mask[(SA[i]) % 8]) ? 1 : 0) &&
         !((t[(SA[i] - 1) / 8] & mask[(SA[i] - 1) % 8]) ? 1 : 0)))
      SA[n1++] = SA[i];
  for (i = n1; i < n; i++) SA[i] = -1;
  int name = 0, prev = -1;
  for (i = 0; i < n1; i++) {
    int pos = SA[i];
    bool diff = false;
    for (int d = 0; d < n; d++)
      if (prev == -1 ||
          (cs == sizeof(int) ? ((int *)s)[pos + d]
                             : ((unsigned char *)s)[pos + d]) !=
              (cs == sizeof(int) ? ((int *)s)[prev + d]
                                 : ((unsigned char *)s)[prev + d]) ||
          ((t[(pos + d) / 8] & mask[(pos + d) % 8]) ? 1 : 0) !=
              ((t[(prev + d) / 8] & mask[(prev + d) % 8]) ? 1 : 0)) {
        diff = true;
        break;
      } else if (d > 0 &&
                 ((pos + d > 0 &&
                   ((t[(pos + d) / 8] & mask[(pos + d) % 8]) ? 1 : 0) &&
                   !((t[(pos + d - 1) / 8] & mask[(pos + d - 1) % 8]) ? 1
                                                                      : 0)) ||
                  (prev + d > 0 &&
                   ((t[(prev + d) / 8] & mask[(prev + d) % 8]) ? 1 : 0) &&
                   !((t[(prev + d - 1) / 8] & mask[(prev + d - 1) % 8]) ? 1
                                                                        : 0))))
        break;
    if (diff) {
      name++;
      prev = pos;
    }
    pos = (pos % 2 == 0) ? pos / 2 : (pos - 1) / 2;
    SA[n1 + pos] = name - 1;
  }
  for (i = n - 1, j = n - 1; i >= n1; i--)
    if (SA[i] >= 0) SA[j--] = SA[i];
  int *SA1 = SA, *s1 = SA + n - n1;
  if (name < n1)
    SA_IS((unsigned char *)s1, SA1, n1, name - 1, sizeof(int));
  else
    for (i = 0; i < n1; i++) SA1[s1[i]] = i;
  bkt = (int *)malloc(sizeof(int) * (K + 1));
  getBuckets(s, bkt, n, K, cs, true);
  for (i = 1, j = 0; i < n; i++)
    if ((i > 0 && ((t[(i) / 8] & mask[(i) % 8]) ? 1 : 0) &&
         !((t[(i - 1) / 8] & mask[(i - 1) % 8]) ? 1 : 0)))
      s1[j++] = i;
  for (i = 0; i < n1; i++) SA1[i] = s1[SA1[i]];
  for (i = n1; i < n; i++) SA[i] = -1;
  for (i = n1 - 1; i >= 0; i--) {
    j = SA[i];
    SA[i] = -1;
    SA[--bkt[(cs == sizeof(int) ? ((int *)s)[j] : ((unsigned char *)s)[j])]] =
        j;
  }
  induceSAl(t, SA, s, bkt, n, K, cs, false);
  induceSAs(t, SA, s, bkt, n, K, cs, true);
  free(bkt);
  free(t);
}
const int maxn = 200000;
int sa[maxn];
int lcp[maxn];
int rk[maxn];
unsigned char *ss;
int min_rotation(string s) {
  int n = (int)s.size();
  s += s;
  int a = 0;
  for (int b = 0; b < n; b++) {
    for (int i = 0; i < n; i++) {
      if (a + i == b || s[a + i] < s[b + i]) {
        b += max(0, i - 1);
        break;
      }
      if (s[a + i] > s[b + i]) {
        a = b;
        break;
      }
    }
  }
  return a;
}
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  auto join = [&](string s) {
    string t = s;
    reverse((t).begin(), (t).end());
    return s + t;
  };
  auto func = [&](string s, int d) {
    s = join(s);
    s = s.substr(d, n);
    if (k == 2) {
      int x = min_rotation(s);
      s = join(s);
      return s.substr(x, n);
    } else if (1 < k) {
      for (int i = (1); i < (min(k - 1, 15)); ++i) {
        s = join(s);
        int ptr = n;
        while (ptr + 1 < n + n && s[ptr + 1] == s[n - 1]) ptr++;
        s = s.substr(ptr - n + 1, n);
      }
      s = join(s);
      int ptr = n - 1;
      while (0 < ptr && s[ptr - 1] == s[n]) ptr--;
      s = s.substr(ptr, n);
    }
    return s;
  };
  string res = s;
  for (int d = (0); d < (n); ++d) {
    chkmin(res, func(s, d));
  }
  cout << res << "\n";
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
