A - At most twice

Languages: C, C++, Java, JavaScript, Tiger, Python, Haskell, Pascal, C#
Time & Memory limits: (details)

Given a positive integer $U$, find the largest integer $L$ such that $L \leq U$ and $L$ does not contain any digit more than twice.

Input

The input consists of a single line that contains an integer $U$ ($1 \leq U \leq 10^{18}$).

Output

Output a line with an integer representing the largest number less than or equal to $U$ that does not contain any digit more than twice.

Sample test(s)

Input
2210102960
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
2210099887
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
1000000000000000000
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
998877665544332211
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
1001223343
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
998877665
--- Showing first 30 lines (click "Copy" to get full content) ---
Input
20152015
--- Showing first 30 lines (click "Copy" to get full content) ---
Output
20152015
--- Showing first 30 lines (click "Copy" to get full content) ---