a = gets.chomp.split("")
n = gets.to_i

def f(a, n)
    return a if n == 0
    return a if a.empty?
    c = a[0..[a.size-1, n].min].min

    b = []
    i = 0
    k = 0
    until i >= a.size || i - k > n
        if a[i] == c
            n -= (i - k)
            k += 1
        else
            b << a[i]
        end
        i += 1
    end
    b += a[i..-1] if i < a.size
    [c] * k + f(b, n)
end
puts f(a, n).join

