Time

12:30:34
23 May 2012
Version for print

Gorynych the Dragon

prb36   In some kingdom Gorynych the Dragon lived.He had N heads and M tails. Ivan-Tsarevich decided slaythe ruiner of human souls, and for this his godmother, Baba-Yaga, presented to him a magic sword, because only it he can kill Gorynych the Dragon. If he cuts off one head, than on that place grows up new head. If he cuts off tail than on that place grows up two tails. If he cuts off two tails, than grows up 1 head. When he cuts off 2 heads only, than grows up nothing. Gorynych, dragon dies in situation when Ivan-Tsarevich cuts off all heads and all tails. Find the minimal quantity of impacts by sword for slaying Gorynych the Dragon.


Specifications

   Input

   Two numbers N, M (0 ≤ N, M ≤ 1000).

   Output

   A unique number, which is the minimal quantity of impacts by sword, or -1, if the slaying of Gorynych the Dragon is impossible.


Problem information

Time Limit: 1 seconds
Memory Limit: 64 MB
Balls for the passed test: 5
Complexity: 34% 210/318

Example

Example input

3 3

Example output

9


← Matches triangles Problems Mail of the sponsor →