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>
const int N = 10000000 + 10;
int n, m;
char s[N], ans[N];
int p[N], q[N], tot;
void duval() {
  for (int i = 0; i < n;) {
    int j = i, k = i + 1;
    for (; k < n && s[j] <= s[k]; ++k) j = (s[j] < s[k] ? i : (j + 1));
    for (p[tot] = i, q[tot++] = k - j; i <= j;) i += k - j;
  }
}
int z[N];
void init() {
  z[0] = 2 * n + 1;
  for (int i = 1, j = 0, r = 0; i <= 2 * n; ++i) {
    z[i] = std::max(std::min(r - i, z[i - j]), 0);
    while (s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] > r) r = i + z[j = i];
  }
}
void solve(char *res, int len) {
  int k = 2 * n + 1 - len;
  int t = z[k];
  strncpy(res, s[t] < s[k + t] ? s : (s + k), len);
}
int main() {
  scanf(" %s%d", s, &m);
  n = strlen(s);
  std::reverse(s, s + n);
  std::reverse_copy(s, s + n, s + n + 1);
  s[n] = '#';
  init();
  duval();
  int l = n;
  for (; tot && m > 2; --m) {
    --tot;
    strncpy(ans + n - l, s + p[tot], l - p[tot]);
    l = p[tot];
    if (q[tot] == 1) {
      for (; tot && q[tot - 1] == 1; l = p[--tot])
        strncpy(ans + n - l, s + p[tot - 1], l - p[tot - 1]);
    }
  }
  if (m == 1 || tot < 2) {
    solve(ans + n - l, l);
  } else {
    static char temp[N];
    strcpy(temp, ans);
    strncpy(ans + n - l, s + p[tot - 1], l - p[tot - 1]);
    strncpy(temp + n - l, s + p[tot - 2], l - p[tot - 2]);
    solve(ans + n - p[tot - 1], p[tot - 1]);
    solve(temp + n - p[tot - 2], p[tot - 2]);
    if (strcmp(temp, ans) < 0) strcpy(ans, temp);
    int k = 0;
    for (int i = 1; i < l; ++i) {
      int a = 2 * n + 1 - l + k;
      int t = z[a];
      if (t < i - k) {
        if (s[a + t] < s[t]) k = i;
      } else {
        t = z[i - k];
        if (s[t] < s[i - k + t]) k = i;
      }
    }
    strncpy(temp + n - l, s + 2 * n + 1 - l, k);
    strncpy(temp + n - l + k, s, l - k);
    if (strcmp(temp, ans) < 0) strcpy(ans, temp);
  }
  puts(ans);
  return 0;
}