Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Next smaller number


Given is a positive integer n 10 18 . You are asked to find the largest integer m such that m < n and m has the same digits as n . If there is no such m , then the output should be 1 . Also return 1 if the next smaller number with the same digits has a leading zero. You are not allowed to use a sorting algorithm.


Examples

Input: 632
Output: 623

Input: 123656789
Output: 123598766

Input: 100
Output: -1