# 20. 找最小数

20

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

const lines = [];
rl.on('line', (line) => {
    lines.push(line);
});
rl.on('close', () => {
    const num = lines[0];
    const k = lines[1];
    const stack=[];
    for(const i of num) {
        while(stack.length > 0 && k > 0 && stack[stack.length - 1] > i) {
            k -= 1;
            stack.pop();
        }
        stack.push(i);
    }
    console.log((stack.slice(0, stack.length - k)).join('').replace(/^0+/, '') || '0')
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23