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;
template <class T>
inline void smin(T& a, T b) {
  if (a > b) a = b;
}
template <class T>
inline void smax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
int lyndon(const T* s, int n, int* d) {
  int r = 0;
  for (int i = 0, j, k; i < n;) {
    for (k = i, j = i + 1; j < n && s[k] <= s[j]; ++j)
      s[k] < s[j] ? k = i : ++k;
    for (d[r++] = i; i <= k; i += j - k)
      ;
  }
  return r;
}
template <class T>
void z_function(const T* s, int n, int* z) {
  z[0] = n;
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    z[i] = i > r ? 0 : min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
char s[10010000], t[10010000], ans[10010000];
char *cur = ans, *c;
int z[10010000], d[10010000], n, K;
void add(const char* src, int l, char*& dst) {
  copy(src, src + l, dst);
  dst += l;
}
void add_suf(int l, char* dst) {
  int c = z[2 * n + 1 - l];
  add((c >= l || s[c] > s[l - 1 - c]) ? s + 2 * n + 1 - l : s, l, dst);
}
int main() {
  scanf("%s%d", s, &K);
  n = strlen(s);
  copy(s, s + n, s + n + 1);
  reverse_copy(s + n + 1, s + n * 2 + 1, s);
  z_function(s, 2 * n + 1, z);
  int m = lyndon(s, n, d) - 1, l = n;
  if (K > 2)
    for (; m >= 0; l = d[m--]) {
      if (s[d[m]] != s[l - 1]) break;
    }
  if (l != n) K--;
  add(s + n + 1, n - l, cur);
  for (; m && K > 2; l = d[m], m--, K--) add(s + d[m], l - d[m], cur);
  if (K == 1 || m <= 0) {
    add_suf(l, cur);
  } else {
    c = t;
    add(ans, n - l, c);
    add(s + d[m], l - d[m], cur);
    add_suf(d[m], cur);
    add(s + d[m - 1], l - d[m - 1], c);
    add_suf(d[m - 1], c);
    if (strcmp(t, ans) < 0) copy(t, t + n, ans);
    int best = 1;
    for (int i = 2; i < l; i++) {
      int p = z[2 * n + 1 - i];
      if (p < i - best) {
        if (s[p] < s[i - 1 - p]) best = i;
      } else {
        p = z[i - best];
        if (p <= best && s[i - best + p] < s[p]) best = i;
      }
    }
    add(ans, n - l, c = t);
    add(s + 2 * n + 1 - l, l - best, c);
    add(s, best, c);
    if (strcmp(t, ans) < 0) copy(t, t + n, ans);
  }
  printf("%s\n", ans);
  return 0;
}