Aki has given Denji an important non-negative integer to relay to Makima. Denji is unfortunately not smart enough to remember numbers or write them down. As his friend, you have given him a four-digit tally-clicker to store the number for him to help him impress Makima. Denji wishes to be lazy efficient; given a non-negative integer
The tally clicker consists of two buttons. The first button increments the value by 1, wrapping to 0000
if the tally currently displays 9999
. The second button shift all 4 digits up by one. Should any digit be 9
, the second button can't be pressed.
Constraints
Input Specification
The first and only line contains a non-negative integer
Output Specification
Output one non-negative integer, the minimum number of clicks to display
Sample Input 1
9999
Sample Output 1
9
Explanation for Sample Output 1
It is optimal to click the second button nine times.
Sample Input 2
101
Sample Output 2
101
Explanation for Sample Output 2
The only possible combination is to click the first button 101 times.
Comments