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, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T, class U>
inline void print(T first, U second) {
  printsp(first);
  println(second);
}
template <class T, class U, class V>
inline void print(T first, U second, V z) {
  printsp(first);
  printsp(second);
  println(z);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
char s[10000111], ans[10000111], tmp[10000111];
char *cur, *t;
int k, l, m;
int z[10000111], L[10000111], n;
int lyndon(char *s, int n) {
  int r = 0;
  for (int i = 0, j, k; i < n;) {
    for (k = i, j = i + 1; j < n and s[k] <= s[j]; j++)
      s[k] < s[j] ? k = i : ++k;
    for (L[r++] = i; i <= k; i += j - k)
      ;
  }
  return r;
}
void zvalue(int n) {
  z[0] = 0;
  for (int i = 1, l = 0, r = 0; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
void append(char *s, int n, char *&d) {
  copy(s, s + n, d);
  d += n;
}
void shuru(int ed, char *d) {
  int m = z[2 * n - ed];
  append((m >= ed or s[m] < s[ed - 1 - m]) ? s : s + 2 * n - ed, ed, d);
}
void solve(char *s, int n) {
  for (int i = 0; i < n; i++) putchar(s[i]);
  puts("");
}
void find() {
  if (k > 2) {
    while (1) {
      if (s[l - 1] != s[L[m]]) break;
      l = L[m--];
      if (m < 0) break;
    }
    if (l != n) append(s + n, n - l, cur), k--;
  }
  while (1) {
    if (k <= 2 or m < 0) break;
    append(s + L[m], l - L[m], cur);
    l = L[m];
    m--;
    k--;
  }
  if (k == 1 or m <= 0) {
    shuru(l, cur);
  } else {
    t = tmp;
    append(s + L[m], l - L[m], cur);
    shuru(L[m], cur);
    append(ans, n - l, t);
    append(s + L[m - 1], l - L[m - 1], t);
    shuru(L[m - 1], t);
    if (strcmp(tmp, ans) < 0) copy(tmp, tmp + n, ans);
    int now = 1, len;
    for (int i = 2; i < l; i++) {
      len = z[2 * n - i];
      if (len < i - now) {
        if (s[len] < s[i - 1 - len]) now = i;
      } else {
        len = z[i - now];
        if (len <= now and s[i - now + len] < s[len]) now = i;
      }
    }
    t = tmp;
    append(ans, n - l, t);
    append(s + 2 * n - l, l - now, t);
    append(s, now, t);
    if (strcmp(tmp, ans) < 0)
      solve(tmp, n);
    else
      solve(ans, n);
    return;
  }
  solve(ans, n);
}
void pre() {
  n = strlen(s);
  for (int i = 0; i < n; i++) s[i + n] = s[i];
  reverse(s, s + n);
  m = lyndon(s, n);
  L[m--] = l = n;
  zvalue(n << 1);
  cur = ans;
}
int main() {
  scanf("%s", s);
  cin >> k;
  pre();
  find();
  return 0;
}