Time limit: 0.05s
Memory limit: 64MB
Input:
Output:
"How many problems do we need for this contest?"
Task
Given a natural number , you need to determine the largest natural number less than or equal to , such that no matter how you rearrange its digits, it is not divisible by .
Input data
The first line will contain the number .
Output data
The first line will contain the required number.
Constraints and clarifications
Example 1
stdin
69
stdout
69
Example 2
stdin
99
stdout
98
Explanation
In the first example, itself is not divisible by , and any rearrangement of its digits (i.e., ) is also not divisible by . Thus, is the largest number that meets the condition.
In the second example, is divisible by . Therefore, we need to find the next largest number less than that is not divisible by in any rearrangement of its digits, which is .