Gorynych the Dragon#36

Gorynych the Dragon

1 second
64 megabytes
Easy

In a distant kingdom, there lived Zmiy Horynych the Dragon, who had heads and tails.

Dobrynya Mykytych decided to defeat this dragon that threatened humanity. To help him, he was given a magical sword—the only weapon capable of slaying Zmiy Horynych the Dragon.

The sword can be used according to the following rules:

The dragon can be slain only if all his heads and all his tails have been removed.

Determine the minimal number of sword strikes required to slay Zmiy Horynych the Dragon or establish that it is impossible.

Input

Two integers , (0 \leq N,\ M \leq 1000).

Output

A single integer—the minimal number of sword strikes needed to slay the dragon, or -1 if it is impossible.

Examples

Example 1

Loading
Loading