#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T& a, T b) {
  a = max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = min(a, b);
}
bool prime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return x > 1;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long kai(long long x, long long y) {
  long long res = 1;
  for (long long i = x - y + 1; i <= x; i++) {
    res *= i;
    res %= (long long)(1e9 + 7);
  }
  return res;
}
long long mod_pow(long long x, long long y, long long m) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % m;
    }
    x = x * x % m;
    y >>= 1;
  }
  return res;
}
long long comb(long long x, long long y) {
  if (y > x) return 0;
  return kai(x, y) *
         mod_pow(kai(y, y), (long long)(1e9 + 7) - 2, (long long)(1e9 + 7)) %
         (long long)(1e9 + 7);
}
long long get_rand(long long MIN, long long MAX) {
  random_device rnd;
  mt19937_64 mt64(rnd());
  uniform_int_distribution<long long> engine(MIN, MAX);
  return engine(mt64);
}
long long n, k;
string s, ans;
void solve1() {
  string ans = "";
  for (long long i = 0; i < n; i++) ans.push_back('z');
  for (long long i = 0; i < n; i++) {
    long long cnt = 0;
    string t = "";
    for (long long j = i; j < n; j++, cnt++) {
      t.push_back(s[j]);
    }
    for (long long j = n - 1; cnt < n; cnt++, j--) {
      t.push_back(s[j]);
    }
    if (t < ans) ans = t;
  }
  cout << ans << endl;
}
void solve2() {
  string ans = "";
  for (long long i = 0; i < n; i++) ans.push_back('z');
  for (long long i = 0; i < n; i++) {
    long long cnt = 0;
    string t = "";
    bool flag = false;
    long long muki = 1;
    for (long long j = i; cnt < n; j += muki, cnt++) {
      t.push_back(s[j]);
      if (j == n - 1) muki = -1;
      if (j == 0) muki = 1;
      if (!flag && s[j] < s[j + muki]) {
        t.push_back(s[j]);
        muki = -1;
        flag = 1;
      }
    }
    chmin(ans, t);
    cnt = 0;
    t = "";
    muki = -1;
    flag = false;
    for (long long j = i; cnt < n; j += muki, cnt++) {
      t.push_back(s[j]);
      if (j == n - 1) muki = -1;
      if (j == 0) muki = 1;
      if (!flag && s[j] < s[j + muki]) {
        t.push_back(s[j]);
        muki = -1;
        flag = 1;
      }
    }
    chmin(ans, t);
  }
  cout << ans << endl;
}
signed main() {
  cin >> n >> k >> s;
  if (k == 1) {
    solve1();
  } else {
    solve2();
  }
}
