The Parquet of the Triangles#47

The Parquet of the Triangles

1 second
64 megabytes
Easy

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 .

Input

The first line contains the dimensions and (1 \leq M, N \leq 100).

The second line contains the numbers of the tiles and .

Output

Output the minimum number of steps required.

Examples

Example 1

Loading
Loading