#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T, typename Monoid>
struct SegmentTree {
    Monoid merge;
    T unity;
    int N;
    vector<T> node;

    SegmentTree(Monoid f, T id) : merge(f), unity(id) {}

    void init(int sz) {
        N = 1;
        while (N < sz) N <<= 1;
        node.assign(2*N,unity);
    }

    void set(int k, const T &val) {node[k+N] = val;}

    void build() {
        for (int i = N-1; i > 0; --i) {
            node[i] = merge(node[i<<1|0], node[i<<1|1]);
        }
    }

    // (0-indexed)
    void update(int x, T val) {
        x += N;
        node[x] = val;
        while (x > 1) {
            x >>= 1;
            node[x] = merge(node[x<<1|0], node[x<<1|1]);
        }
    }

    // [l, r) (0-indexed)
    T get(int l, int r) {
        if (l >= r) return unity;
        T resl = unity, resr = unity;
        l += N; r += N;
        while (l < r) {
            if (l & 1) resl = merge(resl, node[l++]);
            l >>= 1;
            if (r & 1) resr = merge(node[--r], resr);
            r >>= 1;
        }
        return merge(resl, resr);
    }

    template<typename C>
    int binarysearch(int s, const C &check, T &acc, int k, int l, int r) {
        if (r-l==1) {
            acc = merge(acc,node[k]);
            return check(acc) ? k - N : -1;
        }
        int m = (l+r)>>1;
        if(m <= s) return binarysearch(s, check, acc, (k<<1)|1, m, r);
        if(s <= l && !check(merge(acc,node[k]))) {
            acc = merge(acc,node[k]);
            return -1;
        }
        int vl = binarysearch(s, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return binarysearch(s, check, acc, (k<<1)|1, m, r);
    }

    template<typename C>
    int binarysearch(int s, const C &check) {
        T acc = unity;
        return binarysearch(s, check, acc, 1, 0, N);
    }

    T operator[](int x) {return node[x+N];}
};

template<typename T>
struct BinaryIndexedTree {
    int N;
    vector<T> data;

    BinaryIndexedTree(){}
    BinaryIndexedTree(int N) : N(N), data(N+1,0) {}

    // [0,k) (0-indexed) a[0] + … + a[k-1]
    T sum(int k) {
        T ret = 0;
        for(; k > 0; k -= k & -k) ret += data[k];
        return ret;
    }

    // [l,r) (0-indexed) a[l] + …　+ a[r-1]
    T sum(int l, int r) {
        if (l >= r) return 0;
        T vl = sum(l);
        T vr = sum(r);
        return vr - vl;
    }
    // (0-indexed) a[k] += x;
    void add(int k, T x) {
        for(++k; k <= N; k += k & -k) data[k] += x;
    }

    // (0-indexed)
    int lowerbound(T x) {
        int k = 1;
        int ret = 0;
        while ((k<<1) <= N) k <<= 1;
        while (k) {
            if (ret + k <= N && data[ret+k] < x) {
                x -= data[ret+k];
                ret += k;
            }
            k >>= 1;
        }
        return ret;
    }

    // (0-indexed)
    int upperbound(T x) {return lowerbound(x+1);}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();
    int K; cin >> K;

    vector<int> A(N);
    rep(i,N) A[i] = S[i] - 'a';
    auto f=[](pii a, pii b) {return min(a,b);};
    const pii id = pii(1e9,1e9);
    SegmentTree<pii, decltype(f)> seg(f,id);
    seg.init(N);
    rep(i,N) seg.set(i,pii(A[i],i));
    seg.build();

    BinaryIndexedTree<int> BIT(N);
    vector<int> B(N);
    int r = N-1;
    int cur = 0;
    rep(i,N) {
        cur = i;
        while (r < N-1 and (r+1)-BIT.sum(r+1) <= K) r++;
        while (r > 0 and (seg[r]==id or r-BIT.sum(r) > K)) r--;
        auto val = seg.get(0,r+1);
        int cnt = val.second - BIT.sum(val.second);
        K -= cnt;
        B[i] = val.first;
        seg.update(val.second,id);
        BIT.add(val.second,1);
        if (!K) break;
    }
    rep(i,N) if (seg[i] != id) B[++cur] = seg[i].first;

    rep(i,N) cout << char(B[i]+'a');
    cout << ln;
}



Measured memory_bytes: 9660