#include <bits/stdc++.h>
using namespace std;
string rev(string s) {
  reverse(s.begin(), s.end());
  return s;
}
int cons(string s, char ch) {
  int poz = (int)s.size() - 1;
  int rez = 0;
  while (poz >= 0 && s[poz] == ch) {
    poz--;
    ++rez;
  }
  return rez;
}
int main() {
  string s;
  cin >> s;
  char ch = *min_element(s.begin(), s.end());
  int k;
  cin >> k;
  k = min(k, 12);
  auto u = s + rev(s);
  for (int i = 0; i < k - 1; ++i) {
    int best = 0;
    u = s + rev(s);
    string to;
    for (int i = 0; i < (int)s.size(); ++i) {
      string now = u.substr(i, s.size());
      if (cons(now, ch) > best) best = cons(now, ch), to = now;
    }
    s = to;
  }
  u = s + rev(s);
  for (int i = 0; i < (int)s.size(); i++) {
    string now = u.substr(i, s.size());
    if (now < s) s = now;
  }
  cout << s;
}
