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;
inline int read() {
  int res = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * f;
}
namespace qiqi {
const int N = 1e7 + 6;
int n, k, cnt, p[N], q[N], z[N];
char s[N], t[N], ans[N];
inline void Z(char *s, int n) {
  int l = 0, r = 0;
  z[1] = n;
  for (int i = (2); i <= (n); ++i) {
    if (i <= r) z[i] = min(z[i - l + 1], r - i + 1);
    while (s[1 + z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) r = i + z[l = i] - 1;
  }
}
inline void lyd(char *s, int n) {
  int i = 1;
  while (i <= n) {
    int j = i, k = i + 1;
    while (k <= n && s[j] <= s[k]) j = s[j] < s[k++] ? i : j + 1;
    while (i <= j) i += k - j;
    p[++cnt] = i - 1;
    q[cnt] = k - j;
  }
}
inline void solve(char *res, int len) {
  int k = n * 2 + 2 - len;
  strncpy(res, s[1 + z[k]] < s[k + z[k]] ? s + 1 : s + k, len);
}
void main() {
  scanf("%s", s + 1);
  int l = n = strlen(s + 1);
  k = read();
  reverse(s + 1, s + n + 1);
  reverse_copy(s + 1, s + n + 1, s + n + 2);
  s[n + 1] = '#';
  Z(s, n * 2 + 1);
  lyd(s, n);
  while (cnt && k > 2) {
    --k;
    --cnt;
    strncpy(ans + n - l + 1, s + p[cnt] + 1, l - p[cnt]);
    l = p[cnt];
    if (q[cnt + 1] == 1)
      while (q[cnt] == 1) {
        --cnt;
        strncpy(ans + n - l + 1, s + p[cnt] + 1, l - p[cnt]);
        l = p[cnt];
      }
  }
  if (cnt == 1 || k < 2) {
    solve(ans + n - l + 1, l);
    puts(ans + 1);
    return;
  }
  strcpy(t + 1, ans + 1);
  strncpy(ans + n - l + 1, s + p[cnt - 1] + 1, l - p[cnt - 1]);
  strncpy(t + n - l + 1, s + p[cnt - 2] + 1, l - p[cnt - 2]);
  solve(ans + n - p[cnt - 1] + 1, p[cnt - 1]);
  solve(t + n - p[cnt - 2] + 1, p[cnt - 2]);
  if (strcmp(t + 1, ans + 1) < 0) strcpy(ans + 1, t + 1);
  int k = 1, a, b;
  for (int i = (2); i <= (l); ++i) {
    b = z[a = n * 2 + 1 - l + k];
    if (b < i - k) {
      if (s[a + b] < s[1 + b]) k = i;
    } else {
      b = z[i - k + 1];
      if (s[1 + b] < s[i - k + b + 1]) k = i;
    }
  }
  --k;
  strncpy(t + n - l + 1, s + n * 2 + 2 - l, k);
  strncpy(t + n - l + k + 1, s + 1, l - k);
  if (strcmp(t + 1, ans + 1) < 0) strcpy(ans + 1, t + 1);
  puts(ans + 1);
}
}  // namespace qiqi
int main() {
  qiqi::main();
  return 0;
}