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 <typename T>
int duval(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;
}
char s[10010000], ans[10010000], ss[10010000];
int d[10010000], z[10010000];
void makez(int n) {
  int L = 0, R = 0;
  z[0] = n;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  return;
}
int n;
char* cur = ans;
void add(const char* src, int l, char*& dst) {
  copy(src, src + l, dst);
  dst += l;
  return;
}
void add_suf(int l, char* dst) {
  int m = z[2 * n - l];
  add((m >= l || s[m] < s[l - 1 - m]) ? s : s + 2 * n - l, l, dst);
  return;
}
int main() {
  int m, c, K, l, best;
  scanf("%s", s);
  n = strlen(s);
  copy(s, s + n, s + n);
  reverse(s, s + n);
  scanf("%d", &K);
  m = duval(s, n, d) - 1;
  makez(2 * n);
  l = n;
  if (K > 2) {
    while (true) {
      bool ok = false;
      if (s[l - 1] == s[d[m]]) ok = true;
      if (!ok) break;
      m--;
      l = d[m + 1];
      if (m < 0) break;
    }
    if (l != n) {
      add(s + n, n - l, cur);
      K--;
    }
  }
  while (true) {
    if (K <= 2) break;
    if (m < 0) break;
    add(s + d[m], l - d[m], cur);
    l = d[m];
    m--;
    K--;
  }
  if (K == 1 || m <= 0) {
    add_suf(l, cur);
  } else {
    char* t = ss;
    add(s + d[m], l - d[m], cur);
    add_suf(d[m], cur);
    add(ans, n - l, t);
    add(s + d[m - 1], l - d[m - 1], t);
    add_suf(d[m - 1], t);
    if (strcmp(ss, ans) < 0) copy(ss, ss + n, ans);
    best = 1;
    for (int i = 2; i < l; i++) {
      c = z[2 * n - i];
      if (c < i - best) {
        if (s[c] < s[i - 1 - c]) best = i;
      } else {
        c = z[i - best];
        if (c <= best && s[i - best + c] < s[c]) best = i;
      }
    }
    t = ss;
    add(ans, n - l, t);
    add(s + 2 * n - l, l - best, t);
    add(s, best, t);
    ss[n] = 0;
    if (strcmp(ss, ans) < 0) strcpy(ans, ss);
  }
  puts(ans);
  return 0;
}