OC Practice Week 1

Start

2017-09-13 19:00 CEST

OC Practice Week 1

End

2017-09-20 19:00 CEST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -9 days 11:02:14

Time elapsed

168:00:00

Time remaining

0:00:00

Problem A
Veci

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 999\, 999$). 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$.

Sample Input 1 Sample Output 1
156
165
Sample Input 2 Sample Output 2
330
0
Sample Input 3 Sample Output 3
27711
71127