#include<bits/stdc++.h>
using namespace std;

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

const char INF = 'z' + 1;

struct segmentTree{
    int N;
    vector< pair<char, int> > mini;
    
    void init(int siz){
        N = 1;
        while(N < siz){
            N <<= 1;
        }
        mini.resize(N * 2 - 1, {INF, -1});
        return;
    }

    void build(string &dat){
        init(dat.size());
        for(int i = 0, len = dat.size() ; i < len ; ++i){
            mini[i + N - 1] = {dat[i], i};
        }
        for(int i = N - 2 ; i >= 0 ; --i){
            mini[i] = min(mini[i * 2 + 1], mini[i * 2 + 2]);
        }
    }

    void update(int k, char x){
        k += N - 1;
        mini[k].first = x;
        while(k > 0){
            k = (k - 1) / 2;
            mini[k] = min(mini[k * 2 + 1], mini[k * 2 + 2]);
        }
    }

    pair<char, int> getMin(int a, int b, int k, int l, int r){
        if(r <= a || b <= l){
            return {INF, -1};
        }
        if(a <= l && r <= b){
            return mini[k];
        }
        pair<char, int> vl = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
        pair<char, int> vr = getMin(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    pair<char, int> getMin(int a, int b){
        return getMin(a, b, 0, 0, N);
    }
};

struct binaryIndexedTree{
    vector<int> node;
    int n;

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += node[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x){
        ++i;
        while(i <= n){
            node[i] += x;
            i += i & -i;
        }
        return;
    }

    void build(vector<int> &dat){
        n = dat.size();
        node.resize(n + 1);
        for(int i = 0 ; i < n ; ++i){
            add(i, dat[i]);
        }
        return;
    }

    int lower_bound(int k){
        int left = 0, right = n;
        while(right - left > 1){
            int mid = (left + right) / 2;
            if(sum(mid) >= k){
                right = mid;
            }else{
                left = mid;
            }
        }
        return right;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int k;
    cin >> k;

    segmentTree seg;
    seg.build(s);

    vector<int> v(s.size(), 1);
    binaryIndexedTree bit;
    bit.build(v);

    int n = s.size();
    string ans;
    ans.resize(n);
    rep(i, n){
        int r = bit.lower_bound(k + 1);
        pair<char, int> t = seg.getMin(0, r);
        ans[i] = t.first;
        k -= bit.sum(t.second);
        seg.update(t.second, INF);
        bit.add(t.second, -1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9112