A rectangular room of size M \times N (first along the horizontal, then along the vertical) is tiled with triangular tiles, which are numbered as shown in the figure.
In one step, you can move from one tile to an adjacent tile only through a shared side. Find the minimum number of steps required to move from tile to tile .
The first line contains the dimensions and (1 \leq M, N \leq 100).
The second line contains the numbers of the tiles and .
Output the minimum number of steps required.
Example 1