You are playing a game on a grid of size N×M. The game has the following rules:
Write a program to find the path which has the minimum number of changes in direction. Print the number of times that the player needs to turn on the path
Input format
Output format
Print the minimum number of times that the player needs to turn on the required path. If no path exists, print -1.
Constraints
1≤N,M≤103
For the given sample case, Wizard will take first turn at cell (1,4) , second turn at cell (3,4) ,third turn at cell (3,1), and fourth turn at cell (5,1).