Magic machine#4850

Magic machine

1 second
128 megabytes
Very easy

Ibrahim has a black magic machine with three buttons and a display. The display can show at most a four-digit number. Each button changes the displayed number in some way: the first button multiplies the number by , the second adds to it the sum of its digits, and the third button subtracts . If the number becomes negative or exceeds , the machine breaks.

Ibrahim can press the buttons in any order. He wonders how to display the number after some sequence of button presses, starting from the number currently shown on the display. Help him find the minimum number of button presses required.

Input

Two integers and (1 \leq a, b \leq 9999) are given.

Output

Print the minimum number of operations needed to obtain from .

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading