Problem: You are given a non-empty line s and an integer k. The following operation is performed with this line exactly once:

  * A line is split into at most k non-empty substrings, i.e. string s is represented as a concatenation of a set of strings s = t1 + t2 + ... + tm, 1 ≤ m ≤ k. 
  * Some of strings ti are replaced by strings tir, that is, their record from right to left. 
  * The lines are concatenated back in the same order, we get string s' = t'1t'2... t'm, where t'i equals ti or tir. 



Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string s.

Input

The first line of the input contains string s (1 ≤ |s| ≤ 5 000 000), consisting of lowercase English letters. The second line contains integer k (1 ≤ k ≤ |s|) — the maximum number of parts in the partition.

Output

In the single line print the lexicographically minimum string s' which can be obtained as a result of performing the described operation. 

Examples

Input

aba
2


Output

aab


Input

aaaabacaba
2


Output

aaaaabacab


Input

bababa
1


Output

ababab


Input

abacabadabacaba
4


Output

aababacabacabad

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
string reversed(string s) {
  reverse(s.begin(), s.end());
  return s;
}
string min(string s) { return min(s, reversed(s)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int o;
  string s;
  cin >> s >> o;
  int n = s.size();
  s = reversed(s) + "#" + s;
  vector<array<int, 2>> lyndon = {{0, 0}};
  for (int i = 0; i < n;) {
    int j = i + 1, k = i;
    while (j < n && s[j] >= s[k]) {
      if (s[j] > s[k]) {
        k = i;
      } else {
        ++k;
      }
      ++j;
    }
    while (i <= k) {
      i += j - k;
    }
    lyndon.push_back({i, j - k});
  }
  vector<int> z(s.size());
  for (int i = 1, l = 0, r = 0; i < (int)s.size(); ++i) {
    z[i] = (i >= r) ? 0 : min(r - i, z[i - l]);
    for (; i + z[i] < (int)s.size() && s[i + z[i]] == s[z[i]]; ++z[i])
      ;
    if (i + z[i] > r) {
      l = i, r = i + z[i];
    }
  }
  string prefix;
  while (lyndon.size() > 1 && o > 2) {
    int i = 0, p = 0;
    while (p == 0 || (p == 1 && lyndon.back()[1] == 1)) {
      i = lyndon.back()[0], p = lyndon.back()[1];
      ;
      lyndon.pop_back();
      prefix += s.substr(lyndon.back()[0], i - lyndon.back()[0]);
    }
    --o;
  }
  int m = lyndon.back()[0];
  string suffix = min(s.substr(0, m));
  if (o == 2) {
    for (int i = 0; i < min(2, (int)lyndon.size() - 1); ++i) {
      int j = lyndon[lyndon.size() - 2 - i][0];
      suffix = min(suffix, s.substr(j, m - j) + min(s.substr(0, j)));
    }
    int j = 1;
    for (int i = 2; i < m; ++i) {
      int d = i - j, c = 2 * n + 1 - i;
      if (z[c] < d) {
        if (s[z[c]] < s[c + z[c]]) {
          j = i;
        }
      } else {
        if (s[d + z[d]] < s[z[d]]) {
          j = i;
        }
      }
    }
    suffix = min(suffix, reversed(s.substr(j, m - j)) + s.substr(0, j));
  }
  cout << prefix << suffix << "\n";
}