K-digit Number Junior
Medium
Execution time limit is 1 second
Runtime memory usage limit is 8 megabytes
Let's define a number as K-digit if it contains no more than K distinct digits in its decimal representation, ignoring any leading zeros.
Given a number x, your task is to find the nearest K-digit number to it.
Input
The input consists of a single line with two integers, K and x, both without leading zeros (1 ≤ K ≤ 10, 0 ≤ x ≤ 10^8).
Output
Output a K-digit number y such that the absolute difference |y-x| is minimized. If there are multiple such numbers, you may output any one of them.
Examples
Input #1
Answer #1
Submissions 83
Acceptance rate 28%