Deforestation

Cut trees in a grid so the top-left and bottom-right cells become connected, minimizing the total walking time to cut each tree and haul it back to the mill.

Hard8GraphShortest pathDynamic programmingGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

The JOI Kingdom has a wide forest. The forest is a rectangle, divided into a grid of HH cells from north to south and WW cells from west to east. The cell that is ii-th from the north and jj-th from the west (1iH1 \le i \le H, 1jW1 \le j \le W) has Ai,jA_{i,j} trees growing in it. The cell at the northwest corner has a lumber mill, so no tree grows there. That is, A1,1=0A_{1,1} = 0.

A person can enter a cell that has no tree. A person can move to a cell adjacent to the north, south, east, or west of the current cell if that cell has no tree. Nobody can go outside the forest. As a public works project of the kingdom, JOI wants to cut trees so that a person can travel between the northwest corner cell and the southeast corner cell in both directions.

The cutting goes as follows. At the start JOI is at the northwest corner cell, where the lumber mill is. JOI moves in 1 minute to a cell adjacent to the north, south, east, or west of the current cell if that cell has no tree. JOI also cuts one tree in 1 minute from a cell adjacent to the north, south, east, or west of the current cell. Every time JOI cuts one tree, JOI has to carry that tree to the lumber mill at the northwest corner cell. JOI moves at the same speed while carrying a tree. JOI cannot cut another tree while carrying one.

Find the minimum time needed to cut trees so that the condition holds. The cutting time is the time until the last tree that was cut is carried to the lumber mill.

Input

The input is given from standard input in the following format.

H W
A_{1,1} ... A_{1,W}
...
A_{H,1} ... A_{H,W}

Output

Print the minimum time needed to cut trees so that the condition holds, on one line.

Constraints

  • 1H301 \le H \le 30
  • 1W301 \le W \le 30
  • (H,W)(1,1)(H, W) \ne (1, 1)
  • 0Ai,j100000 \le A_{i,j} \le 10000 (1iH1 \le i \le H, 1jW1 \le j \le W)
  • A1,1=0A_{1,1} = 0