The calculator machine

Javier likes electronics and tinkering with machines. His son Luis is now learning to calculate with numbers, and Javier has built for him a machine with a display in which four digits are shown, and there are three buttons marked with the tags +1, ∗2 and ÷3. When the buttons are pressed the value in the display is updated by performing the corresponding operation (to add one, to multiply by two or to divide by three). Since the display has only four digits, the operations are performed modulo 10,000 and division is integer division. Luis has perfectly understood how the machine works and uses it to verify that the calculations he mentally performs before pressing a button are correct. Now Javier has challenged him to a game: he sets the display to show a specific number and asks Luis to obtain a different number by pressing the buttons as few times as possible. Can you help them by computing the smallest number of keystrokes to get the final number from the original one? Input The program will respond to a series of test cases. Each case consists of a single line with two numbers (from 0 to 9,999), the one which originally appears on the display and the one that Luis has to obtain by pressing the buttons on the calculator machine. Output For each test case, the fewest keystrokes required to get the final number from the original one will be written on a single line. Sample Input 0 1024 5000 0 9999 6666 Sample Output 11 1 2