# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, dp[210000], a[210000], b[210000];
string str, ss;
bool f[210000];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
vector<Edge>vec[200000];
vector<LL>v[26];
struct cll {
	char first;
	LL second, thrid;
};
vector<cll>S;
map<string, LL>ma;
multiset<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
class BIT {
public:
	vector<LL> Bit;
	LL M;
	BIT(LL M) :
		Bit(vector<LL>(M + 1, 0)), M(M) {}
	LL sum(LL i) {
		LL s = 0;
		while (i>0) {
			s += Bit[i];
			i -= (i&(-i));
		}
		return s;
	}
	LL sum(LL i, LL j) {
		return sum(j) - sum(i - 1);
	}
	//1-index
	void add(LL i, LL x) {
		while (i <= M) {
			Bit[i] += x;
			i += (i&(-i));
		}
	}
	//初めてk以上になる、index
	int lower_bound(LL k) {
		int l = -1, r = M + 1, m;
		while (r - l > 1) {
			m = (l + r) / 2;
			if (sum(m) >= k)
				r = m;
			else l = m;
		}
		return (r == M + 1 ? M + 1 : r);
	}
	//初めてkより大きくなる、index
	int upper_bound(LL k) {
		int l = -1, r = M + 1, m;
		while (r - l > 1) {
			m = (l + r) / 2;
			if (sum(m) > k)
				r = m;
			else l = m;
		}
		return (r == M + 1 ? M + 1 : r);
	}
};

BIT bit(210000);

struct Seg {
	LL n;
	vector<Pll>node;
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = Pll(INF, -1);
		Mfor(i, n - 2)node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
		//区間最小などの時
		//rep(i, n * 2 - 1)lazy[i] = -1;
	}

	void update(LL i,Pll x) {
		i = i + n - 1;
		node[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}

 Pll find(LL i, LL a, LL b, LL l, LL r) {
		if (b< l || r < a)return Pll(INF,-1);
		if (l <= a && b <= r)return node[i];
		return min(find(i * 2 + 1, a, (a + b) / 2, l, r), find(i * 2 + 2, (a + b + 1) / 2, b, l, r));
	}
};

Seg seg(210000);

int main() {
	cin >> str;

	cin >> n;
	rep(i, str.size()) {
		bit.add(i+1, 1);
		seg.update(i, Pll(str[i] - 'a', i));
	}
	rep(i, str.size()) {
		int r = bit.upper_bound(max(n, (LL)0));
		Pll num = seg.find(0, 0, seg.n - 1, 0, r-1);
		cout << str[num.sec];
		n -= bit.sum(num.second);
		bit.add(num.second+1, -1);
		seg.update(num.second, Pll(INF, -1));
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 17840