Your program will be given an integer $X$. Find the smallest number larger than $X$ consisting of the same digits as $X$.
Input
The first line of input contains the integer $X$ ($1 \le X \le 999999$). The first digit in $X$ will not be a zero.
Output
Output the result on a single line. If there is no such number, output $0$.
Example 1
Input
156
Output
165
Example 2
Input
330
Output
0
Example 3
Input
27711
Output
71127
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.