#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i;
string s,s1,res;
getline(cin,s);
cin>>n;
for(i=0;i<s.size();i++)
if(s[i]>='0'&&s[i]<='9') s1+=s[i];
stack<char> s2;
for(i=0;i<s1.size();i++)
{
while(!s2.empty()&&s2.top()<s[i]&&(s2.size()-1+s1.size()-i)>=n) s2.pop();
if(s2.size()<n) s2.push(s1[i]);
}
while(!s2.empty())
{
res=s2.top()+res;
s2.pop();
}
cout<<res;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IG1haW4oKQp7CiAgICBpbnQgbixpOwogICAgc3RyaW5nIHMsczEscmVzOwogICAgZ2V0bGluZShjaW4scyk7CiAgICBjaW4+Pm47CiAgICBmb3IoaT0wO2k8cy5zaXplKCk7aSsrKQogICAgaWYoc1tpXT49JzAnJiZzW2ldPD0nOScpIHMxKz1zW2ldOwogICAgc3RhY2s8Y2hhcj4gczI7CiAgICBmb3IoaT0wO2k8czEuc2l6ZSgpO2krKykKICAgIHsKICAgICAgICB3aGlsZSghczIuZW1wdHkoKSYmczIudG9wKCk8c1tpXSYmKHMyLnNpemUoKS0xK3MxLnNpemUoKS1pKT49bikgczIucG9wKCk7CiAgICAgICAgaWYoczIuc2l6ZSgpPG4pIHMyLnB1c2goczFbaV0pOwogICAgfQogICAgd2hpbGUoIXMyLmVtcHR5KCkpCiAgICB7CiAgICAgICAgcmVzPXMyLnRvcCgpK3JlczsKICAgICAgICBzMi5wb3AoKTsKICAgIH0KICAgIGNvdXQ8PHJlczsKfQo=