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;
const int maxn = 10000050;
int Lyndom(char *buf, int n, int *pos) {
  int r = 0;
  for (int i = 0, j, k; i < n;) {
    for (k = i, j = i + 1; j < n and buf[k] <= buf[j]; ++j)
      buf[k] < buf[j] ? k = i : ++k;
    for (pos[++r] = i; i <= k; i += j - k)
      ;
  }
  return r;
}
void Z_function(char *buf, 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 and buf[z[i]] == buf[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
char buf[maxn], ans[maxn], rans[maxn];
char *cur = ans, *rcur = rans;
int z[maxn], pos[maxn], n, k, m;
void add(const char *src, int l, char *&c) {
  copy(src, src + l, c);
  c += l;
}
void add_suf(int l, char *c) {
  int w = z[2 * n + 1 - l];
  add((w >= l || buf[w] > buf[l - 1 - w]) ? buf + 2 * n + 1 - l : buf, l, c);
}
int l, best;
int main() {
  scanf("%s", buf);
  n = strlen(buf);
  scanf("%d", &k);
  copy(buf, buf + n, buf + n + 1);
  reverse_copy(buf + n + 1, buf + 2 * n + 1, buf);
  m = Lyndom(buf, n, pos);
  Z_function(buf, 2 * n + 1, z);
  l = n;
  if (k > 2)
    for (; m; l = pos[m--])
      if (buf[pos[m]] != buf[l - 1]) break;
  if (l != n) k--;
  add(buf + n + 1, n - l, cur);
  for (; m > 1 and k > 2; l = pos[m--], k--) add(buf + pos[m], l - pos[m], cur);
  if (k == 1 or m <= 1) {
    add_suf(l, cur);
  } else {
    add(ans, n - l, rcur);
    add(buf + pos[m], l - pos[m], cur);
    add_suf(pos[m], cur);
    add(buf + pos[m - 1], l - pos[m - 1], rcur);
    add_suf(pos[m - 1], rcur);
    if (strcmp(rans, ans) < 0) copy(rans, rans + n, ans);
    best = 1;
    for (int i = 2; i < l; i++) {
      int p = z[2 * n + 1 - i];
      if (p < i - best) {
        if (buf[p] < buf[i - p - 1]) best = i;
      } else {
        p = z[i - best];
        if (p <= best and buf[i - best + p] < buf[p]) best = i;
      }
    }
    rcur = rans + n - l;
    add(buf + 2 * n + 1 - l, l - best, rcur);
    add(buf, best, rcur);
    if (strcmp(rans, ans) < 0) copy(rans, rans + n, ans);
  }
  puts(ans);
  return 0;
}