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;
int n, m, k, i, j, z[10000005];
string st, sr, stt;
vector<int> pos, len;
void lyndon(int n) {
  int i, j, k;
  for (i = 1; i <= n;) {
    j = i;
    k = i + 1;
    while (k <= n && sr[j] <= sr[k]) {
      if (sr[j] == sr[k])
        j++;
      else
        j = i;
      k++;
    }
    pos.push_back(i);
    len.push_back(k - j);
    while (i + (k - j) <= k) i += k - j;
  }
  pos.push_back(n + 1);
}
void getz(int n) {
  int i, l = 0, r = 0;
  for (i = 2; i <= n; i++) {
    if (i < r) {
      z[i] = min(z[i - l + 1], r - i);
    }
    while (i + z[i] <= n && stt[z[i] + 1] == stt[i + z[i]]) z[i]++;
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
}
struct node {
  string ans;
  void add0(const string &st, int l, int len) {
    int i;
    for (i = 0; i < len; i++) {
      ans.push_back(st[l + i]);
    }
  }
  void add1(const string &st, int l, int len) {
    int i;
    for (i = len - 1; i >= 0; i--) {
      ans.push_back(st[l + i]);
    }
  }
  void add2(const string &st, int l, int len) {
    string tmp, tmp2;
    int i;
    for (i = 0; i < len; i++) {
      tmp.push_back(st[l + i]);
    }
    tmp2 = tmp;
    reverse(tmp2.begin(), tmp2.end());
    ans += min(tmp, tmp2);
  }
} ans1, ans2, ans3;
int main() {
  cin >> st >> k;
  n = st.size();
  st = " " + st;
  sr = st;
  reverse(sr.begin() + 1, sr.end());
  lyndon(n);
  stt = sr + st;
  st[n + 1] = '#';
  getz(n + n + 1);
  m = pos.size() - 2;
  while (k > 2 && m >= 0) {
    if (len[m] == 1) {
      while (m >= 0 && len[m] == 1) {
        ans1.add0(sr, pos[m], pos[m + 1] - pos[m]);
        m--;
      }
    } else {
      ans1.add0(sr, pos[m], pos[m + 1] - pos[m]);
      m--;
    }
    k--;
  }
  if (k == 1 || m < 1) {
    ans1.add2(sr, 1, pos[m + 1] - 1);
  } else {
    ans2 = ans1;
    ans3 = ans1;
    ans2.add0(sr, pos[m], pos[m + 1] - pos[m]);
    ans2.add2(sr, 1, pos[m] - 1);
    ans1.add0(sr, pos[m - 1], pos[m + 1] - pos[m - 1]);
    ans1.add2(sr, 1, pos[m - 1] - 1);
    if (ans2.ans < ans1.ans) ans1 = ans2;
    int p = n - pos[m + 1] + 2, q = p;
    for (i = p + 1; i <= n; i++) {
      char c1, c2;
      if (p + z[p + n + 1] < i) {
        c1 = st[p + z[p + n + 1]];
        c2 = sr[z[p + n + 1] + 1];
      } else {
        int h = min(z[i - p + 1], n - i);
        c1 = sr[h + 1];
        c2 = sr[h + (i - p + 1)];
      }
      if (c1 < c2) {
        p = i;
      }
    }
    ans3.add0(st, n - pos[m + 1] + 2, p - (n - pos[m + 1] + 2));
    ans3.add1(st, p, n - p + 1);
    if (ans3.ans < ans1.ans) ans1 = ans3;
  }
  cout << ans1.ans << endl;
  return 0;
}