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;
char s[10000011], T[10000011], S[5][10000011], t[10000011];
int P[10000011], Len, L[10000011], len, nxt[10000011], cnt, K;
void Lyndon() {
  for (int i = 1; i <= len;) {
    int j = i, k = i + 1;
    while (k <= len && s[k] >= s[j]) {
      if (s[k] > s[j])
        j = i;
      else
        j++;
      k++;
    }
    P[++cnt] = i;
    L[cnt] = k - j;
    while (i <= j) {
      i += (k - j);
    }
  }
}
void solve1(int n) {
  for (int i = 1; i <= n; i++) S[1][i] = s[n - i + 1];
}
void solve2(int n) {
  int p = 1;
  for (int i = 1; i <= n; i++) t[i] = t[n + i] = s[i];
  for (int i = 1, j = 2, k = 0; i <= n && j <= n;) {
    j = max(j, i + 1);
    while (t[i + k] == t[j + k] && k < n) k++;
    if (k == n) {
      p = i;
      break;
    }
    if (t[i + k] > t[j + k])
      i = i + k + 1;
    else
      j = j + k + 1;
    p = i;
    k = 0;
  }
  for (int i = 1; i <= n; i++) S[2][i] = t[p + i - 1];
}
void solve3(int n) {
  nxt[1] = n;
  int p = 0, maxx = 0;
  for (int i = 1; i <= n; i++) t[i + n] = s[n - i + 1];
  for (int i = 2; i <= n * 2; i++) {
    if (i < maxx) nxt[i] = min(maxx - i, nxt[i - p + 1]);
    while (i + nxt[i] <= n * 2 && t[i + nxt[i]] == t[1 + nxt[i]]) nxt[i]++;
    if (i + nxt[i] > maxx) maxx = i + nxt[i], p = i;
  }
  p = 1;
  for (int i = 2; i < n; i++) {
    int t1 = nxt[n + n + 1 - i];
    if (t1 != i - p) {
      if (t[n + n - i + 1 + t1] > t[t1 + 1]) p = i;
    } else {
      t1 = nxt[i - p + 1];
      if (t[t1 + 1] > t[i - p + t1 + 1]) p = i;
    }
  }
  for (int i = 1; i <= n - p; i++) S[3][i] = s[n - i + 1];
  for (int i = 1; i <= p; i++) S[3][n - p + i] = s[i];
}
void solve4(int n) {
  int p = cnt;
  while ((P[p + 1] - P[p]) * 2 <= (P[p] - P[p - 1])) {
    int flag = 0;
    for (int i = P[p] - 1; i >= P[p - 1]; i--) {
      if (s[i] < s[n - i + P[p - 1]]) {
        flag = 1;
        break;
      }
      if (s[i] > s[n - i + P[p - 1]]) break;
    }
    if (flag) break;
    p--;
  }
  for (int i = 1; i <= n - P[p] + 1; i++) S[4][i] = s[P[p] + i - 1];
  for (int i = 1; i < P[p]; i++) S[4][i + n - P[p] + 1] = s[P[p] - i];
}
void solve(int n) {
  solve1(n);
  solve2(n);
  solve3(n);
  solve4(n);
  int p = 1;
  for (int i = 2; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      if (S[i][j] == S[p][j])
        continue;
      else {
        if (S[i][j] < S[p][j]) p = i;
        break;
      }
    }
  }
  printf("%s", T + 1);
  printf("%s", S[p] + 1);
}
void Extend(int l, int r) {
  for (int i = l; i <= r; i++) T[++Len] = s[i];
}
void solve0(int n) {
  for (int i = 1; i <= n; i++) {
    S[1][i] = s[i];
    S[2][i] = s[n - i + 1];
  }
  int p = 1;
  for (int i = 1; i <= n; i++) {
    if (S[2][i] < S[1][i])
      p = 2;
    else if (S[2][i] > S[1][i])
      break;
  }
  for (int i = 1; i <= n; i++) printf("%c", S[p][i]);
}
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  scanf("%d", &K);
  if (K == 1) {
    solve0(len);
    return 0;
  }
  for (int i = 1; i < len - i + 1; i++) {
    swap(s[i], s[len - i + 1]);
  }
  Lyndon();
  P[cnt + 1] = len + 1;
  while (cnt && K >= 3) {
    Extend(P[cnt], P[cnt + 1] - 1);
    if (L[cnt] != 1 || L[cnt - 1] != 1) K--;
    cnt--;
  }
  if (cnt) {
    solve(P[cnt + 1] - 1);
  } else {
    for (int i = 1; i <= Len; i++) printf("%c", T[i]);
  }
  return 0;
}