favorite We need a little bit of your help to keep things running, click on this banner to learn more
Problems

# Gorynych the Dragon

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.

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.

Time limit 1 second
Memory limit 64 MiB
Input example #1
3 3

Output example #1
9

Author Анатолий Присяжнюк