3nplus1II

After you have defeated the Chocolate Gym, Gym Leader Joseph has given you a magical Toblerone bar.

This Toblerone bar is very special. Your Toblerone bar start with a certain length. If the length is odd, the Toblerone bar will grow to 3*(current length)+1 in the next minute. If the length is even, the Toblerone bar will shrink by half in the next minute.

The toblerone keeps repeating this pattern until the Toblerone bar is of length 1. Afterwhich, the Toblerone bar will simply cease to exist. For example, if the length of the Toblerone bar at time = 1 is 5, the sequence is:

5 16 8 4 2 1

At time = 1, the length is 5; At time = 2, the length is 16; At time = 3, the length is 8 and so on. After time = 6, the Toblerone bar will cease to exist.

Your task is simple: given the initial length of the Toblerone bar, find the length of the Toblerone bar at that certain time. If the Toblerone bar does not exist by that time, output -1.

Input

The input will consist of two integers, the starting Toblerone length and the time in which you want to find what length the Toblerone has become. Both integers are at most 10 000.

Output

The length of the Toblerone at that time.

Sample Input

7 5

Sample Output

17

Submitting .cpp to '3nplus1II'


You're not logged in! Click here to login


Compile Errors


							
Time Limit: 1 Seconds
Memory Limit: 256MB
No. of ACs: 204
Your best score: 0
Source: Classic Problem

Subtask Score
1 100
2 0