#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
int k, n, vt = 1;
pair<int, int> a[1000001], tree[4000001];
void setup(int id, int l, int r)
{
if (l == r)
{
tree[id] = a[l];
return;
}
int mid = (l + r) / 2;
setup(id * 2, l, mid);
setup(id * 2 + 1, mid + 1, r);
if (tree[id * 2].first >= tree[id * 2 + 1].first)
tree[id] = tree[id * 2];
else
tree[id] = tree[id * 2 + 1];
}
pair<int, int> get_val(int id, int l, int r, int u, int v)
{
if (l > v || r < u)
return make_pair(-1, -1);
if (l >= u && r <= v)
return tree[id];
int mid = (l + r) / 2;
pair<int, int> left = get_val(id * 2, l, mid, u, v);
pair<int, int> right = get_val(id * 2 + 1, mid + 1, r, u, v);
if (left.first >= right.first)
return left;
else
return right;
}
void inp()
{
getline(cin, s);
cin >> k;
n = s.size();
k = n - k;
s = 'x' + s;
for (int i = 1; i <= s.size() - 1; i++)
a[i] = make_pair(s[i] - '0', i);
setup(1, 1, n);
}
void xuli()
{
while (k > 0)
{
pair<int, int> ans = get_val(1, 1, n, vt, n - k + 1);
cout << ans.first;
vt = ans.second + 1;
k--;
}
}
int main()
{
inp();
xuli();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgczsKaW50IGssIG4sIHZ0ID0gMTsKcGFpcjxpbnQsIGludD4gYVsxMDAwMDAxXSwgdHJlZVs0MDAwMDAxXTsKCnZvaWQgc2V0dXAoaW50IGlkLCBpbnQgbCwgaW50IHIpCnsKCWlmIChsID09IHIpCgl7CgkJdHJlZVtpZF0gPSBhW2xdOwoJCXJldHVybjsKCX0KCglpbnQgbWlkID0gKGwgKyByKSAvIDI7CglzZXR1cChpZCAqIDIsIGwsIG1pZCk7CglzZXR1cChpZCAqIDIgKyAxLCBtaWQgKyAxLCByKTsKCWlmICh0cmVlW2lkICogMl0uZm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