Time limit
2s
Memory limit
128 MB
Youngsik counts numbers with his left hand. He starts with his thumb, then counts with his index finger, middle finger, ring finger, and little finger in order. After reaching the little finger, he counts back in the opposite direction: ring finger, middle finger, index finger, and thumb. He repeats this pattern until he reaches the number he wants, never skipping a finger.
For example, when counting to 10, he uses the fingers in this order: thumb, index, middle, ring, little, ring, middle, index, thumb, index.
One of Youngsik's left-hand fingers is injured. He cannot count with his right hand, so he must keep using his left hand, but there is a limit on how many times he can count with the injured finger.
Find the largest number Youngsik can count to.
The first line contains the number of Youngsik's injured finger. The fingers are numbered 1, 2, 3, 4, and 5 from the thumb to the little finger.
The second line contains how many times he can count with the injured finger. This value is an integer from 0 to 1,000,000,000 inclusive.
Print the largest number Youngsik can count to. If he cannot even count the first number, print 0.