The white chess king set out on a journey and arrived in a new country. After much wandering, he settled in a country somewhat reminiscent of his homeland. Here is a map of this country:

Here he began to wander the field, moving from one cell to another, but only if they share a common side. One day, while lodging at field , he wondered what was the minimum number of moves needed to reach field . Help the wandering white king solve this pseudo-chess puzzle.
The input file contains two positive integers and , each not exceeding 10^6.
Output the minimum number of moves needed for the wandering king to reach field .
Esempio 1