Surround the Castle

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You just started a simulation game of the Age of Civil Wars! In this game, there is an infinite two-dimensional grid. Each cell in this grid is either a plain cell, a castle cell or a moat cell.

Your territory is a rectangle of cells that consists of RR rows and CC columns. Your territory now consists of only one castle cell and the other RC1RC - 1 plain cells. You can change each plain cell to a moat cell by paying some costs depending on the cell.

To protect your castle cell from foreign enemies, you decided to surround your castle cell with moat cells. More precisely, your castle cell is considered surrounded by moat cells if any cell outside your territory can't be reached from your castle cell by repeatedly moving to a cell that is not your moat cell and is horizontally, vertically, or diagonally adjacent to the current cell.

Figures D-1 to D-3 show examples of your territories whose borders are depicted as bold rectangles. In Figure D-1 the moat cells, which are depicted as blue squares, surround the castle cell. On the other hand, in Figures D-2 and D-3 the moat cells don't surround the castle cells.

Figure D-1. An example of a castle cell surrounded by moat cells

Figure D-2. An example of a castle cell not surrounded by moat cells

Figure D-3. Another example of a castle cell not surrounded by moat cells

You are given the location of your castle cell and the cost to change each of the other plain cells to a moat cell. Find the minimum total cost to surround your castle cell with moat cells.

입력

The input consists of a single test case of the following format.

RR CC

a_11a\_{11} \dots a_1Ca\_{1C}

\vdots

a_R1a\_{R1} \dots a_RCa\_{RC}

RR and CC represent the number of rows and columns of your territory (3R203 \le R \le 20, 3C1043 \le C \le 10^4). Each a_ija\_{ij} (a_ij=1a\_{ij} = -1 or 1a_ij1091 \le a\_{ij} \le 10^9) gives the information of the cell of the ii-th row and the jj-th column of your territory. If it is 1-1, then the cell is your castle cell. Otherwise, the cell is initially a plain cell and a_ija\_{ij} equals the cost to change it to a moat cell.

It is guaranteed that there is exactly one castle cell in the input. In addition, your castle cell never locates at the first row, the RR-th row, the first column nor the CC-th column. In other words, it is guaranteed that you can surround your castle cell with moat cells.

출력

Output the minimum total cost to surround your castle cell with moat cells.