cho.sh
Notes
Loading...

Equal Digit Counts

Time limit

2s

Memory limit

128 MB

Problem

Call a positive integer X an equal-digit-count number if every digit that appears in the decimal representation of X appears the same number of times. Digits that do not appear are ignored. For instance, 2013 satisfies this condition because every appearing digit occurs once, while 2008 does not because 0 occurs twice and 2 and 8 occur once.

Given a natural number N, find the smallest equal-digit-count number that is greater than or equal to N.

Input

The first line contains a natural number N. N is at most 10^18.

Output

Print the answer on the first line. The answer is at most 9,223,372,036,854,775,807.