题目描述
Problem Description
Takahashi's calculator is broken. If more than $ K $ different types of digits are entered, the calculator will break.
An integer $ A $ is given. Takahashi wants to enter this integer. However, if he tries to enter the integer normally, the calculator might break. Therefore, he will enter the integer with the smallest possible difference from $ A $ without breaking the calculator.
At this time, output how large the difference between the integer Takahashi enters and the integer $ A $ will be.
Input Format
The input is given from the standard input in the following format:
$ A $ $ K $
- The first line contains the integer $A\ (1\ ≦\ A\ ≦\ 10^{15})$ and the number of different types of digits that can be entered $K\ (1\ ≦\ K\ ≦\ 10)$, separated by spaces.
Output Format
Output the minimum value of the difference between the integer Takahashi enters and the integer $ A $ in one line. Include a newline at the end of the output.
Sample Input and Output
Sample Input #1
1234 2
Sample Output #1
12
Sample Input #2
800000 1
Sample Output #2
22223
Sample Input #3
7328495 10
Sample Output #3
0
Sample Input #4
262004 2
Sample Output #4
218
Notes/Hints
Partial Points
- Correctly solving all cases where $1\ ≦\ A\ ≦\ 100,000$ will award $ 30 $ points.
- Correctly solving the remaining cases will award an additional $ 70 $ points.
Sample Explanation 1
Takahashi can only enter up to $ 2 $ different types of keys. In this case, entering $ 1222 $ will be the closest to $ 1234 $, and the difference is $ 12 $.
Sample Explanation 2
Since only $ 1 $ type of digit can be used, $ 777777 $ is the closest integer.
Sample Explanation 3
In this case, Takahashi's calculator is actually not broken. Therefore, he can enter the given integer as it is.
Sample Explanation 4
$ 262222 $ is the closest integer.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分