eolymp
bolt
Try our new interface for solving problems
Problems

Gorynych the Dragon

Gorynych the Dragon

\includegraphics{https://static.e-olymp.com/content/13/133385affefb5b9f254c74380de015ff316967c9.gif} In some kingdom Gorynych the Dragon lived.He had \textbf{N} heads and \textbf{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. \InputFile Two numbers \textbf{N}, \textbf{M} (0 ≤ \textbf{N}, \textbf{M} ≤ 1000). \OutputFile A unique number, which is the minimal quantity of impacts by sword, or -1, if the slaying of Gorynych the Dragon is impossible.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3 3
Output example #1
9
Author Анатолий Присяжнюк