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[10001000];
int n;
vector<int> sep;
void lindon() {
  for (int i = 0; i < n;) {
    sep.push_back(i);
    int p1 = i, p2 = i + 1;
    while (p2 < n && s[p1] <= s[p2]) {
      if (s[p1] == s[p2])
        ++p1, ++p2;
      else
        p1 = i, ++p2;
    }
    int len = p2 - p1;
    while (i <= p1) i += len;
  }
}
int z[10001000];
void exkmp() {
  int id, mx = -1;
  for (int i = 1; i <= 2 * n; ++i) {
    int p = 0;
    if (mx > i) p = max(p, min(mx - i, z[i - id]));
    while (p <= 2 * n && s[p] == s[i + p]) ++p;
    z[i] = p;
    if (i + p > mx) id = i, mx = i + p;
  }
  z[0] = 2 * n + 1;
}
string ans;
bool same(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}
int T, m;
void rua3() {
  sep.push_back(n);
  m = sep.size() - 2;
  while (T >= 3 && m >= 0) {
    ans += string(s + sep[m], sep[m + 1] - sep[m]);
    --m;
    if (!(m >= 0 && same(string(s + sep[m], sep[m + 1] - sep[m])) &&
          same(string(s + sep[m + 1], sep[m + 2] - sep[m + 1]))))
      --T;
  }
}
int rev(int x) { return 2 * n - x; }
string fix(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return min(s, t);
}
string gaolas() {
  int l = sep[m + 1];
  string res = fix(string(s, l));
  if (T <= 1 || m <= 0) return res;
  {
    int mn = 0;
    char c1, c2;
    for (int i = 1; i < l - 1; ++i) {
      int lcp1 = z[rev(i)];
      if (lcp1 < i - mn) {
        c1 = s[i - lcp1];
        c2 = s[lcp1];
      } else {
        int lcp2 = z[i - mn];
        c1 = s[lcp2];
        c2 = s[i - mn + lcp2];
      }
      if (c1 > c2) mn = i;
    }
    string t1(s, mn + 1), t2(s + mn + 1, l - mn - 1);
    reverse(t2.begin(), t2.end());
    string t = t2 + t1;
    res = min(res, t);
  }
  for (int i = m; i >= 0 && i >= m - 1; --i) {
    string t1 = fix(string(s, sep[i])), t2 = string(s + sep[i], l - sep[i]);
    string t = t2 + t1;
    res = min(res, t);
  }
  return res;
}
int main() {
  scanf("%s%d", s, &T);
  n = strlen(s);
  for (int i = 0; i < n; ++i) s[i + n + 1] = s[i];
  reverse(s, s + n);
  s[n] = 0;
  lindon();
  exkmp();
  rua3();
  ans += gaolas();
  printf("%s\n", ans.c_str());
}