Shortest Path Problem

All submissions for this problem are available.
Consider a two dimensional array of numbers comprehended between 0 and 9(as shown below). The Matrix can be traversed following any orthogonal direction (i.e., north, south, east and west). Considering that each cell represents a cost, Your task is to find the minimum cost value to go from the topleft corner to the bottomright corner of a given number array of size NxM where 1 <= N, M <= 999. Note that the solution for the given example is 24.
0 3 1 2 9 7 3 4 9 9 1 7 5 5 3 2 3 4 2 5
Input
The input contains several Test cases. Each test case is defined by: one line with the number of rows, N; one line with the number of columns, M; and N lines, one per each row of the Matrix, containing the numbers separated by spaces. Terminate the input with (no. of rows)N=0.
Output
For each maze, output one line with the required minimum value.
Example
Input: 4 5 0 3 1 2 9 7 3 4 9 9 1 7 5 5 3 2 3 4 2 5 1 6 0 1 2 3 4 5 0 Output: 24 15
Author:  rscrbv 
Tags  rscrbv 
Date Added:  19012010 
Time Limit:  3 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 