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;
struct ANS {
  char str[5000010];
  int len;
  ANS() { len = 0; }
  void extend(char* s, int l, bool rev = false) {
    if (!rev) {
      for (int i = 0; i < l; i++) str[++len] = s[i];
    } else {
      for (int i = l - 1; i >= 0; i--) str[++len] = s[i];
    }
    return;
  }
  void solve(char* s, int l) {
    for (int i = 0; i < l; i++)
      if (s[i] < s[l - i - 1]) {
        extend(s, l, false);
        return;
      } else if (s[i] > s[l - i - 1]) {
        extend(s, l, true);
        return;
      }
    extend(s, l);
    return;
  }
  bool operator<(const ANS& x) const {
    for (int i = 1; i <= len; i++)
      if (str[i] < x.str[i])
        return true;
      else if (str[i] > x.str[i])
        return false;
    return false;
  }
} ans, tmp1, tmp2;
char s[10000010];
int n;
int z[10000010];
void initZ(int len) {
  z[1] = len;
  for (int i = 2, j = 1, k = 1; i <= len; i = k) {
    if (j < i) j = i;
    while (j <= len && s[j] == s[j - i + 1]) j++;
    z[i] = j - i;
    k = i + 1;
    while (k + z[k - i + 1] < j) {
      z[k] = z[k - i + 1];
      k++;
    }
  }
  return;
}
int pos[10000010], l[10000010], cnt;
void lyndon() {
  int i = 1, j, k;
  while (i <= n) {
    j = i;
    k = i + 1;
    while (k <= n && s[k] >= s[j]) {
      if (s[k] > s[j])
        j = i;
      else
        j++;
      k++;
    }
    pos[cnt] = i;
    l[cnt] = k - j;
    cnt++;
    while (i <= j) i += k - j;
  }
  return;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  reverse(s + 1, s + n + 1);
  for (int i = 1; i <= n; i++) s[2 * n - i + 2] = s[i];
  s[n + 1] = '#';
  initZ(2 * n + 1);
  lyndon();
  pos[cnt] = n + 1;
  cnt--;
  int k;
  scanf("%d", &k);
  while (k > 2 && cnt) {
    if (l[cnt] == 1) {
      while (cnt && l[cnt] == 1) {
        ans.extend(s + pos[cnt], pos[cnt + 1] - pos[cnt]);
        cnt--;
      }
    } else {
      ans.extend(s + pos[cnt], pos[cnt + 1] - pos[cnt]);
      cnt--;
    }
    k--;
  }
  if (!cnt || k == 1)
    ans.solve(s + 1, pos[cnt + 1] - 1);
  else {
    tmp2 = tmp1 = ans;
    ans.extend(s + pos[cnt], pos[cnt + 1] - pos[cnt]);
    tmp1.extend(s + pos[cnt - 1], pos[cnt + 1] - pos[cnt - 1]);
    ans.solve(s + 1, pos[cnt] - 1);
    tmp1.solve(s + 1, pos[cnt - 1] - 1);
    if (tmp1 < ans) ans = tmp1;
    int res = pos[cnt + 1] - 1;
    for (int i = pos[cnt + 1] - 2; i >= 0; i--) {
      int p = z[n * 2 - res + 2];
      if (p < res - i) {
        if (s[res - p] < s[p + 1]) res = i;
      } else {
        p = z[res - i + 1];
        if (s[p + 1] < s[res - i + p + 1]) res = i;
      }
    }
    tmp2.extend(s + res + 1, pos[cnt + 1] - res - 1, true);
    tmp2.extend(s + 1, res);
    if (tmp2 < ans) ans = tmp2;
  }
  printf("%s", ans.str + 1);
  return 0;
}