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;
string s, t, ts, ans;
int pos[10000005], len[10000005], tot;
inline string reverse(string s) {
  string t;
  t.resize(s.size());
  int n = s.size();
  for (int i = 0; i < n; i++) t[n - i - 1] = s[i];
  return t;
}
void Duval(const string& s) {
  int n = s.size();
  for (int i = 0; i < n;) {
    int j = i, k = i + 1;
    while (s[j] <= s[k]) {
      if (s[j] == s[k])
        ++j;
      else
        j = i;
      ++k;
    }
    len[++tot] = k - j;
    while (i <= j) {
      pos[tot] = i + k - j - 1;
      i += k - j;
    }
  }
}
int p[10000005];
void Exkmp(const string& s) {
  int n = s.size();
  int mid = 0, mx = 0;
  p[0] = n;
  for (int i = 1; i < n; i++) {
    if (i <= mx) p[i] = min(p[i - mid], mx - i + 1);
    while (s[i + p[i]] == s[p[i]]) ++p[i];
    if (i + p[i] - 1 > mx) mid = i, mx = i + p[i] - 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  t = reverse(s);
  int k;
  cin >> k;
  if (k == 1) return cout << min(s, t), 0;
  Duval(t);
  pos[0] = -1;
  while (k > 2 && tot) {
    if (len[tot] == 1) {
      while (tot && len[tot] == 1)
        ans += t.substr(pos[tot - 1] + 1, pos[tot] - pos[tot - 1]), --tot;
      --k;
    } else
      ans += t.substr(pos[tot - 1] + 1, pos[tot] - pos[tot - 1]), --k, --tot;
  }
  if (tot == 0) return cout << ans, 0;
  if (tot == 1) {
    string tmp = t.substr(0, pos[1] + 1);
    tmp = min(tmp, reverse(tmp));
    cout << ans + tmp;
    return 0;
  }
  s = reverse(t = t.substr(0, pos[tot] + 1));
  ts = t + "#" + s;
  Exkmp(ts);
  string tmp = min(s, t);
  int cut = 0, n = s.size();
  for (int i = 1; i < n; i++) {
    int cl = min(i - cut, p[n + 1 + cut]);
    if (cut + cl == i) cl += p[cl];
    cl = min(cl, n - cut);
    if ((cl < i - cut ? s[cut + cl] : t[cut + cl - i]) < t[cl]) cut = i;
  }
  tmp = min(tmp, s.substr(0, cut) + t.substr(0, n - cut));
  string las = t.substr(pos[tot - 1] + 1, len[tot]);
  string lass = t.substr(pos[tot - 2] + 1, len[tot]);
  int st = pos[tot - 1] + 1;
  string tt = t.substr(st, n - st);
  string res = t.substr(0, n - tt.size());
  tt += min(res, reverse(res));
  tmp = min(tmp, tt);
  if (las == lass) {
    st = pos[tot - 2] + 1;
    tt = t.substr(st, n - st);
    res = t.substr(0, n - tt.size());
    tt = tt + min(res, reverse(res));
    tmp = min(tmp, tt);
  }
  cout << ans + tmp;
  return 0;
}