Magic machine#529

Magic machine

1 second
128 megabytes
Medium (≈1350)

Ibrahim has a black magic machine. It has three buttons and a display. Display can show no more than a four-digit number. Each of the buttons changes the number in some way: the first is multiplies it by 3, the second adds to it the sum of digits, and the third button subtracts 2. If the number becomes negative or greater than 9999, the machine breaks.

Ibrahim can press the buttons in any order. He wondered how to get on the display the number b after a certain sequence of clicks, if currently the machine shows a. Help him to find the minimum number of keystrokes.

Input

Two integers a and b (1 ≤ a, b ≤ 9999).

Output

Print the minimal number of operations to get b from a.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading