#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;

class SegmentTree{
public:
	int n = 1;
	vector<P> seg[2];
	//m要素のセグメントツリー作成
	void init(int m){
		while(n < m)n *= 2;
		rep(i,2)seg[i].resize(2*n);
		fill(all(seg[0]), P(-INF, -1));
		fill(all(seg[1]), P(INF, -1));
	}
	P cmp_min(P x, P y){
		if(x.fi == y.fi)return x.se < y.se ? x : y;
		return min(x, y);
	}
	P cmp_max(P x, P y){
		if(x.fi == y.fi)return x.se < y.se ? x : y;
		return max(x, y);
	}
	//kの値をxに変更
	void update(int k, int x, bool flag=false){
		k += n-1;
		seg[0][k] = seg[1][k] = P(x, k-(n-1));
		if(flag){seg[0][k] = P(-INF, -1);seg[1][k] = P(INF, -1);}
		while(k > 0){
			k = (k-1)/2;
			seg[0][k] = cmp_max(seg[0][k*2+1], seg[0][k*2+2]);
			seg[1][k] = cmp_min(seg[1][k*2+1], seg[1][k*2+2]);
		}
	}
	void erase(int k){
		update(k, -1, true);
	}
	P calc_max(int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return P(-INF, -1);
		if(a <= l && r <= b)return seg[0][k];
		P vl = calc_max(a, b, k*2+1, l, (l+r)/2);
		P vr = calc_max(a, b, k*2+2, (l+r)/2, r);
		return cmp_max(vl, vr);
	}
	P calc_min(int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return P(INF, -1);
		if(a <= l && r <= b)return seg[1][k];
		P vl = calc_min(a, b, k*2+1, l, (l+r)/2);
		P vr = calc_min(a, b, k*2+2, (l+r)/2, r);
		return cmp_min(vl, vr);
	}
	//[a,b)の最大値を求める
	P get_max(int a, int b){return calc_max(a, b, 0, 0, n);}
	//[a,b)の最小値を求める
	P get_min(int a, int b){return calc_min(a, b, 0, 0, n);}
};

class BIT{
public:
	int n = 1;
	vector<int> bit;
	void init(int m){	//[1, m]のBIT作成
		while(n < m+1)n *= 2;
		bit.resize(n+1);
		fill(all(bit), 0);
	}
	void add(int i, int x){
		while(i <= n){bit[i] += x;i += i&-i;}
	}
	int get(int i){
		int s = 0;
		while(i > 0){s += bit[i];i -= i&-i;}
		return s;
	}
	int lower_bound(int k, int ret = -1){	//ret=見つからなかったときに返すidx
		int lb = 0, ub = n+1;
		while(ub-lb > 1){
			if(get((lb+ub)/2) >= k)ub = (lb+ub)/2;
			else lb = (lb+ub)/2;
		}
		return ub == n+1 ? ret : ub;
	}
};

SegmentTree seg;
BIT bit;
signed main(){
	string str;
	int k;
	cin >> str >> k;
	int n = str.size();
	seg.init(n+1);
	bit.init(n);
	str = " "+str;k++;
	rrep(i,n){seg.update(i, str[i]-'a');bit.add(i, 1);}
	
	string ans;
	rrep(i,n){
		int idx = bit.lower_bound(k, n);
		P p = seg.get_min(0, idx+1);
		//printf("%lld %lld %lld\n", k, idx, p.se);
		k -= bit.get(p.se)-1;
		bit.add(p.se, -1);
		seg.erase(p.se);
		ans.pb('a'+p.fi);
	}
	cout << ans << endl;
	return 0;
}



