Remove K Digits

easy monotonic-stack stack greedy strings 1000 ms · 256 MB

Remove K Digits

You are given a non-negative integer written as a string s of n decimal digits (the string may start with zeros). Delete exactly k of its digits; the remaining digits keep their original order and are read as a decimal number.

Find the smallest number you can obtain.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^6).

The second line contains the string s of exactly n characters, each a digit from 0 to 9.

Output

Print the smallest obtainable number in decimal without leading zeros. If the remaining digits are all zeros, or no digits remain at all (when k = n), print 0.

Notes

In the first example, deleting the digits 4, 3 and 2 from 1432219 leaves 1219, and no other choice of three digits gives a smaller number.

In the second example, deleting the leading 1 of 10200 leaves 0200, which is the number 200.

Example 1

Input

7 3
1432219

Output

1219

Example 2

Input

5 1
10200

Output

200

Hints · reveal one at a time if you're stuck

Hint 1

Since every candidate has the same length, the leftmost digits matter most. When is deleting a digit better than keeping it? Look at what happens when a digit is followed by a smaller one.

Hint 2

Scan the digits from left to right and keep the kept digits in a stack: while deletions remain and the top is larger than the current digit, pop it. Afterwards, spend any leftover deletions at the end, then strip leading zeros.

report an issue Prefer your own editor? sooks prep 36 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.