cho.sh
Notes
Loading...

Digit Swap

Time limit

2s

Memory limit

128 MB

Problem

You are given an integer N that does not start with 0. Let M be the number of digits in N. Perform the following operation exactly K times.

Choose two positions i and j, counted from the left, such that 1 <= i < j <= M. Swap the digits at those two positions. The number after the swap must not start with 0.

Find the largest number that can be made after performing exactly K operations.

Input

The first line contains the integers N and K. N is a positive integer not greater than 1,000,000 and does not start with 0. K is a positive integer not greater than 10.

Output

Print the largest number that can be made after performing exactly K operations. If it is impossible to perform all K operations, print -1.