Route in the matrix#4110

Route in the matrix

1 second
122.174 megabytes
Easy

Given a matrix of size n \times m that contains non-negative integers, not greater than .

The cells are adjacent if their column or row numbers differ by . The path from one cell to another passes only through adjacent cells of the matrix.

Find the path with minimum cost between the upper left and lower right corners of the matrix. The cost of the path equals the sum of matrix elements along the path. It is allowed to move to neighboring cells to the left, right, up, and down.

Input

First line contains the numbers and (1 \leq n, m \leq 10). Then lines are given, each line contains numbers.

Output

Print the cost of minimal path.

Examples

Example 1

Loading
Loading