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
#include <bits/stdc++.h>
using namespace std;
struct pat {
  int x, y;
  pat(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator<(const pat &p) const { return x == p.x ? y < p.y : x < p.x; }
};
namespace RKK {
const int N = 5000011;
char str[N], srt[N << 1], prt[N];
int n, kap;
void cmp(char *s) {
  for (int i = 1; i <= n; i++) {
    if (s[i] > prt[i])
      return;
    else if (s[i] < prt[i])
      break;
  }
  memcpy(prt, s, (n + 1) * sizeof(char));
}
int ep[N], T[N], cnt;
void lyndon() {
  int i = 1, j, k;
  while (i <= n) {
    for (j = i, k = i + 1; k <= n && str[k] >= str[j]; k++)
      str[k] > str[j] ? j = i : j++;
    while (i <= j) i += k - j;
    cnt++, ep[cnt] = i - 1, T[cnt] = k - j;
  }
}
int ex[N], p[N];
void exkmp(char *s, int n, char *t, int m) {
  ex[1] = m;
  for (int i = 2, l = 0, r = 0; i <= m; i++) {
    if (i <= r) ex[i] = min(ex[i - l + 1], r - i + 1);
    while (i + ex[i] <= m && t[i + ex[i]] == t[1 + ex[i]]) ex[i]++;
    if (i + ex[i] - 1 > r) l = i, r = i + ex[i] - 1;
  }
  for (int i = 1, l = 0, r = 0; i <= n; i++) {
    if (i <= r) p[i] = min(ex[i - l + 1], r - i + 1);
    while (i + p[i] <= n && s[i + p[i]] == t[1 + p[i]]) p[i]++;
    if (i + p[i] - 1 > r) l = i, r = i + p[i] - 1;
  }
}
void work1() {
  reverse(str + 1, str + 1 + n);
  cmp(str);
  reverse(str + 1, str + 1 + n);
}
void work2() {
  for (int i = 1; i <= n; i++) srt[i] = srt[i + n] = str[i];
  int i = 1, j, k, lst, m = n << 1;
  while (i <= n) {
    lst = i - 1;
    for (j = i, k = i + 1; k <= m && srt[k] >= srt[j]; k++)
      srt[k] > srt[j] ? j = i : j++;
    while (i <= j) i += k - j;
  }
  cmp(srt + lst);
}
void work3() {
  for (int i = 1; i <= n; i++) srt[i] = str[i];
  reverse(srt + 1, srt + 1 + n);
  exkmp(srt, n, str, n);
  reverse(p + 1, p + 1 + n);
  int o = n;
  for (int i = n - 1; i; i--) {
    if (p[o - 1] < o - i) {
      if (str[o - 1 - p[o - 1]] < str[p[o - 1] + 1]) o = i;
    } else if (ex[o - i + 1] < i - 1) {
      if (str[ex[o - i + 1] + 1] < str[o - i + 1 + ex[o - i + 1]]) o = i;
    }
  }
  reverse(srt + 1, srt + 1 + n), reverse(srt + 1, srt + o),
      reverse(srt + 1, srt + 1 + n);
  cmp(srt);
}
void work4() {
  int x = cnt + 1, y, flag = 0;
  while (--x > 1) {
    for (int i = ep[x - 1] + 1, j = ep[x - 2] + 1; i <= ep[x]; i++, j++)
      if (str[i] != str[j]) {
        flag = 1;
        break;
      }
    if (flag) break;
  }
  y = x;
  while (++y <= cnt) {
    for (int i = ep[y - 1], j = ep[y - 2] + n - i + 1; i > ep[y - 2];
         i--, j++) {
      if (str[i] < str[j]) x = y;
      if (str[j] != str[i]) break;
    }
  }
  reverse(str + 1 + ep[x - 1], str + 1 + n);
  reverse(str + 1, str + 1 + n);
  cmp(str);
}
int main() {
  scanf("%s%d", str + 1, &kap), n = strlen(str + 1);
  if (kap == 1) {
    for (int i = 1, j = n; i <= n; i++, j--) {
      if (str[i] < str[j])
        break;
      else if (str[j] < str[i]) {
        reverse(str + 1, str + 1 + n);
        break;
      }
    }
    printf("%s\n", str + 1);
    return 0;
  }
  reverse(str + 1, str + 1 + n);
  lyndon();
  while (cnt && kap > 2) {
    for (int i = ep[cnt - 1] + 1; i <= ep[cnt]; i++) putchar(str[i]);
    if (T[cnt] != 1 || T[cnt - 1] != 1) kap--;
    cnt--;
  }
  n = ep[cnt];
  if (n) {
    memcpy(prt, str, (n + 1) * sizeof(char));
    work1(), work2(), work3(), work4();
  }
  for (int i = 1; i <= n; i++) putchar(prt[i]);
  return 0;
}
}  // namespace RKK
int main() { return RKK::main(); }
