#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


//Base class for Segment Trees
template <class T>
class segtree_base
{
protected:
	size_t width;
	vector<T> vec;
	T def;
	virtual T query_raw(int l_, int r_, int a_, int b_, int k_) = 0;
public:
	segtree_base(size_t size_, T def_ = T()) : def(make_pair('{', 364364))
	{
		width = 1;
		while (width < size_)width *= 2;
		vec.resize(width * 2 - 1, def);
	}
	//Ask a query in ranges [left,right)
	T query(int left, int right)
	{
		return query_raw(left, right, 0, width, 0);
	}
	//Get the number of child nodes
	size_t treeWidth()
	{
		return width;
	}
	virtual ~segtree_base() {}
};

#include <algorithm>
//Range Minimum Tree
template <class T, class Comp>
class rmq_tree : public segtree_base<T>
{
public:
	rmq_tree(size_t size_) : segtree_base<T>(size_, Comp::defval)
	{}

	//Do [] <= base
	void init(const vector<T>&base)
	{
		for (int i = 0; i < min(this->width, base.size()); i++) this->vec[i + this->width - 1] = base[i];
		for (int i = this->width - 2; i >= 0; i--) this->vec[i] = std::min(this->vec[i * 2 + 1], this->vec[i * 2 + 2], Comp());
	}

	//Make [index] <= val;
	void update(int index, T val)
	{
		auto &vec = this->vec;
		index += (this->width - 1);
		vec[index] = val;
		while (index > 0)
		{
			index = (index - 1) / 2;
			vec[index] = std::min(vec[index * 2 + 1], vec[index * 2 + 2], Comp());
		}
	}
private:
	T query_raw(int l_, int r_, int a_, int b_, int k_)override
	{
		const auto &vec = this->vec;
		if (l_ <= a_ && b_ <= r_)
		{
			return vec[k_];
		}
		if (b_ <= l_ || r_ <= a_)
		{
			return this->def;
		}
		int m = (a_ + b_) / 2;
		return std::min(
			query_raw(l_, r_, a_, m, k_ + k_ + 1),
			query_raw(l_, r_, m, b_, k_ + k_ + 2), Comp());
	}
};

template <class T>
struct fenwick_tree {
	vector<T> x;
	fenwick_tree(int n) {
		int N = 1;
		while (n > N)
		{
			N *= 2;
		}
		x.resize(N + 1, 0);
	}
	T sum(int i, int j) {
		if (i > j)return 0;
		if (i == 0) {
			T S = 0;
			for (j; j >= 0; j = (j & (j + 1)) - 1) S += x[j];
			return S;
		}
		else return sum(0, j) - sum(0, i - 1);
	}
	void add(int k, T a) {
		for (; k < x.size(); k |= k + 1) x[k] += a;
	}
};

//Functors for Segment Trees
template <class T>
struct my_less : std::less<T>
{
	static constexpr T defval = std::numeric_limits<T>::max();
};
template <class T>
struct my_greater : std::greater<T>
{
	static constexpr T defval = std::numeric_limits<T>::min();
};

int main(void)
{
	string S;
	LL K;
	cin >> S >> K;
	LL N = S.size();
	rmq_tree<pair<char, int>, my_less<pair<char, int>>>seg(N);
	fenwick_tree<LL> flag(N);
	for (int i = 0; i < N; ++i)
	{
		seg.update(i, make_pair(S[i], i));
		flag.add(i, 1);
	}
	string answer;
	for (int i = 0; i < N; ++i)
	{
		int lo = 0, hi = N;
		int ans = -1;
		if (flag.sum(0, hi - 1) <= K + 1)
		{
			ans = hi;
		}
		else
		{
			while (lo + 1 < hi)
			{
				int mid = (lo + hi) / 2;
				if (flag.sum(0, mid - 1) >= K + 1)
				{
					hi = mid;
				}
				else
				{
					lo = mid;
				}
			}
			ans = hi;
		}
		auto res = seg.query(0, ans);
		char C = res.first;
		answer.push_back(C);
		K -= flag.sum(0, res.second) - 1;
		seg.update(res.second, make_pair('{', 114514));
		flag.add(res.second, -1);
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 9680