[Question]
  [
Let `A` be an `m` by `n` rectangular matrix of **positive** integers, where `m` and `n` are also **positive** integers.
We are interested in RoD ('Right-or-Down') paths from the upper-left cell of `A` to the lower right cell; in an RoD path, each successive cell of the path is either one cell to the Right of or one cell Down from the previous cell.
Given any such RoD path, we can take the sum of the cells in `A` in that path.
For example, consider the 4 by 3 matrix:
```
[ [1, 2, 3, 4],
  [5, 1, 6, 7],
  [8, 2, 1, 1] ]
```
Then we can consider the RoD path:
```
1 > 2   3   4
    v
5   1   6   7
    v
8   2 > 1 > 1
```
which has a sum of `1+2+1+2+1+1=8`. It's worth noting that this path has the smallest sum of all possible RoD paths from upper left to lower right in that matrix.
So, the proposed challenge is to provide the shortest function/program in your language of choice that outputs the minimum sum an RoD path from upper left to lower right can have in a given matrix `A`.
The usual forbidden loopholes are in effect. Your input can be in any reasonable format; your output must be an integer.
This is code-golf; answers are scored by number of bytes.
## Test Cases
```
[ [5] ] -> 5
[ [5, 2] ] -> 7
[ [5], 
  [2] ] -> 7
[ [ 9 , 1 , 12, 3 ],
  [ 12, 11, 6 , 11],
  [ 12, 9 , 2 , 11] ] -> 40
[ [ 6 , 8 , 11, 2 ],
  [ 3 , 6 , 7 , 6 ],
  [ 6 , 2 , 8 , 12] ] -> 37
[ [ 4 , 5 , 8 , 4 ],
  [ 6 , 5 , 9 , 4 ],
  [ 2 , 5 , 6 , 8 ] ] -> 31
[ [ 4 , 5 , 15, 18, 30],
  [ 26, 26, 3 , 4 , 5 ],
  [ 7 , 9 , 29, 25, 14],
  [ 16, 1 , 27, 13, 27],
  [ 23, 11, 25, 24, 12],
  [ 17, 23, 7 , 14, 5 ] ] -> 94
[ [ 10, 15, 7 , 2 , 9 ],
  [ 24, 5 , 2 , 1 , 25],
  [ 2 , 12, 14, 30, 18],
  [ 28, 4 , 12, 22, 14],
  [ 15, 21, 21, 11, 4 ],
  [ 21, 15, 21, 29, 9 ] ] -> 103
```
  
[Answer]
# [J](http://jsoftware.com/), 42 bytes
```
v(+}.<.}:)&.>/@{.[:</.(2#v=._1+1#.$){.!._]
```
[Try it online!](https://tio.run/##ZVDLagJBELz7FZUYoouTcbtn9jGDK4GAp5xyDUEkREIuuXkRv31T7ehBAr09/ajq6t6f8d7P9hgyZnCokfk9eby8vW7Gw3xx8it/ytWjXy@fj/49r5Z@rtPD4LeykKl/qI7@zm8/xmqysxkJAlEEZ14ELZ3LjBMsn3x9fv9iV579NYg1BqwtLUNa9MZVh8C4Q@usplbVwgjdLSOiYTc6whpKRRKUEQdd8PIfL7QeoXbQ1ixY1VGOq9LY5TzhAdAOEuiJDOfFGmjkLlSRzmrsk1ukUryVktqUCENyRmvsR3CEs1eNGIjomfIAq6gWZQLFjILne@RaSkhFSupw0Rr/AA "J – Try It Online")
### How it works
```
v(+}.<.}:)&.>/@{.[:</.(2#v=._1+1#.$){.!._]
                         v=._1+1#.$         Sum of two dimensions - 1; assign to v
                                            (v is a verb)
                      (2#          ){.!._]  Extend the given array in both dimensions
                 [:</.  Extract the antidiagonals as boxed arrays
v             @{.  Take the first `v` antidiagonals
 (       )&.>/     Reduce over unboxed items:
   }.<.}:            Given the right item R, take the minimum of R[1:] and R[:-1]
  +                  Add to the left item
```
### Illustration
```
1 2 3 4  Input array, dimensions = 3,4
5 1 6 7
8 2 1 1
1 2 3 4 _ _  Extended to 6,6 with filler _ (infinity)
5 1 6 7 _ _
8 2 1 1 _ _
_ _ _ _ _ _
_ _ _ _ _ _
_ _ _ _ _ _
1            Diagonalize and take first 6 rows
5 2
8 1 3
_ 2 6 4
_ _ 1 7 _
_ _ _ 1 _ _
Reduction: left+min(right[1:], right[:-1])
1                                          1  => 8
5 2                               5  2  => 10 7
8 1 3                   8 1 3  => 12 5 11
_ 2 6 4      _ 2 6 4 => _ 4 8 12
_ _ 1 7 _ => _ _ 2 8 _
_ _ _ 1 _ _
```
[Answer]
# JavaScript (ES6), ~~78~~ ~~77~~ 76 bytes
```
m=>(M=g=s=>(v=(m[y]||0)[x])?g(s+=v,y++)|g(s,x++,y--)*x--|M<s?M:M=s:0)(x=y=0)
```
[Try it online!](https://tio.run/##hVLLboMwELzzFT7iYhq/gDiqmy/gCxCHKE1QqiRUpYpA4t@p14/AIWkPqzW7s@PZwZ@7267bf5@@ftJr@3GYjnq66Pe41I3uTL7p@FIN9ThSXPU13jZxl@gbGZIEj@ZM@iQhQ5rilz5Nx/Kt25abUncbiuNeD5riad9eu/Z8eD23TXyMqwihCmWojmqM0WqFsih6jCCIz6jiGaom9vA/VBlCBsEJEmEMPhgjKIcGWxSVvd4WA6@kj4lhdo0cDw/EAjnSwmZfzD2pRfM7sXiiWBpY5uFyyQFFtSxyX3RSZmL2NzHLTKyNHTTw5MSGsORktrfwN3JlAqZk8Cp3rvLCZAE5UAnviEFzaff1EwYJTaBkkiyfgpKP9TLqtBbeP3XfWxL/ULyKbGGI/bcStoMtQ2PtNoMm58tFQCdzAbpnbxmZm8peHvQyKqZf "JavaScript (Node.js) – Try It Online")
### Commented
```
m => (                      // m[] = input matrix
  M =                       // initialize the minimum M to a non-numeric value
  g = s =>                  // g = recursive function taking the current sum s
    (v = (m[y] || 0)[x]) ?  //   if the current cell v is defined:
      g(s += v, y++) |      //     do a recursive call at (x, y + 1)
      g(s, x++, y--) * x--  //     do a recursive call at (x + 1, y)
      |                     //     if at least one call did not return 0 (which means
                            //     that we haven't reached the bottom-right corner)
      M < s ?               //     or M is less than s (false if M is still non-numeric):
        M                   //       return M unchanged
      :                     //     else:
        M = s               //       update M to s, and return this new value
    :                       //   else (we're outside the bounds of the matrix):
      0                     //     return 0
)(x = y = 0)                // initial call to g with s = x = y = 0
```
[Answer]
## Haskell, ~~63~~ 57 bytes
```
f x@((a:_:_):c:d)=a+min(f$c:d)(f$tail<$>x)
f x=sum$id=<<x
```
[Try it online!](https://tio.run/##fVHLboMwELznK/bAAVQf4sU8BVX/o0IRKkW1CjRKUom/p/twwyFVhVYLs7PjGfPRXz/fp2nbRlhf4rivT/Upqd/qIWn7p9kv8RjxB7Vb76cmel6TA1Hb6/cc@aFtmnWbe79AC8PXAeB88csNIhjhlZ4KDFguNJBCZwjiV2sN5AzbO8RMVAi6Bx0ml6CLqDopqEYhXaA8aAgTSQcehByNskBx@xZD1Q5hgPTYf4VsRlVSuqNu5kYqFTGmCFwEfayoeMNp8FyvBwvqKXcVSUNSYqKTLMImFo9YzDrR/suZPaqrItxGFTI5NYzhl2B2jyq/xHEGzqJwqf55hLgbZkdWix3@3pc1@6iSI6HbfgA "Haskell – Try It Online")
```
f x@((a:_:_):c:d)=           -- if it's at least a 2x2 matrix
   a+min                     -- add the top left element to the minimum of the
                             -- path costs of
        f$c:d                --   the matrix with the first row dropped and
        f$tail<$>x           --   the matrix with the first column dropped
f x=                         -- else, i.e. a 1xm or nx1 matrix, i.e. a vector
    sum$id=<<x               -- return the sum of this vector
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~38~~ ~~36~~ ~~30~~ 29 bytes
*Thanks to [@Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) for pointing out a mistake, now corrected.*
```
lyZyqsG&nghZ^Yc!tsGz=Z)Ys)sX<
```
[Try it online!](https://tio.run/##y00syfn/P6cyqrKw2F0tLz0jKi4yWbGk2L3KNkozslizOMLm//9oQx0FIx0FYx0FE2sFUx0FINdMR8HcWsECLA7kGsYCAA) Or [verify all test cases](https://tio.run/##RVBBDoIwELz7inoxMemBbluQoDcTPuBBIRiNBz2oicGD@Hmc2RpNWJadmc5OuR2f1/EwXodmePT17H6@NPvdafrs6/eqme/6eb9djtt189qMbewmbbRG2CptpTUOj1jjK20OY86WRvAKQgp0kXipjFdVgXfFD0kcHYM1UadglIpqwkF0oM1P5ljQ@gw0fVCwJokDRdrPoi4gUq55BYzz7Djmv6F4scAQkIEnThm9sM9laVuhYUvGSREkOUbNp38gMA9zAVpoGMIi3wg841Jxr97M2T@OuGX3AQ).
### Explanation
```
l        % Push 1
y        % Input, implicit. Duplicate from below. Pushes the input below
         % the current 1, and a copy of the input on top
Zy       % Size of input. Gives [m, n]
qs       % Subtract 1 element-wise, sum. Gives m+n-2
G        % Push input again
&n       % Push size as two separate numbers. Gives m, n
gh       % Transform n into 1 and concatenate horizontally. Gives [m, 1]
Z^       % Cartesian power of [m, 1] raised to m+n-2. This produces the
         % Cartesian tuples as row of a matrix. A typical tuple may be
         % [1, m, 1, m, m]. This will define a path along the matrix in
         % linear, column-wise indexing (down, then across). So 1 means
         % move 1 step down, and m means move m steps "down", which is
         % actually 1 step to the right
Yc       % Concatenate strcat-like. This prepends the 1 that is at the
         % bottom of the stack to each row
!        % Transpose. Each tuple (extended with initial 1) is now a column
!ts      % Duplicate, sum of each column
Gz       % Number of nonzeros of input. Gives m*n-1
=Z)      % Keep only columns that sum m*n. That means that, starting from
Ys       % Cumulative sum of each column. This defines the path
)        % Index: pick entries specified by the path
s        % Sum of each column
X<       % Minimum
         % Display, implicit
```
[Answer]
# [R](https://www.r-project.org/), 90 bytes
```
function(m){l=sum(m|1)
if(l>1)for(i in 2:l)m[i]=m[i]+min(m[i-1],m[max(0,i-nrow(m))])
m[l]}
```
[Try it online!](https://tio.run/##fY1NCsJADIX3PUWXE0zB6c/YivUU7koXtTAQmExhbLGinr1mdoLgIi8v4X1J2Gx6ytLNLn6cafKK4ena28KKXxoSssqdNdgpKErJp/nRAXfUt1F2TJLvKNM9csfDqvZImQ/TXa5ADwl3rn9vVvEwB1rVqBrUqHMsomiNJorYBuMIGNG2wOsj9gtA8oUarGM6wgYPUka8rPL/WImVpEpJV/KmFKYSX/9C2wc "R – Try It Online")
The naive solution: iterate through the array (down the columns), replacing each entry by the sum of itself and the minimum of its above and to-the-left neighbors, if they exist, then return the last entry.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~57~~ 54 bytes
```
my&f={|.flat&&.[0;0]+min (f(.[1..*]),f $_>>[1..*])||0}
```
[Try it online!](https://tio.run/##VVFda8MwDHzvrxCshHTzgiU7H2YsfySE0ocZCu02ur2UZb89sywn8R6E8el0urM/326XZp6v98K//kyVv5y@i6Ia9Isen67ndyh9WQ1YVY/jQXnYH/s@3aZJ/85fpzv4cn88gP@47XYDDOBAAXKRAgOj2kEA@YKooOEGZiCzScDAhQd47sFqUWJyBzJIi5IBUWnjmcAmqUQ2bUqmFSUb8Dr1bT7EoMtBSqDszpTwvxLWobqQUC@DjYplohqTUqNNK8iF4im7xG/koagNp@FzkTIpc2CTjYnSRGBykyXRxh2rQWfFIGox16YncWsyK84p/Q/VWeT4P5bjcKyl0UkUbhLlztkYSrHR7fVQbU0Xl68GUZv5Dw "Perl 6 – Try It Online")
### Explanation
```
my&f={                                               }  # Function f
      |.flat&&  # Return empty slip if matrix is empty
              .[0;0]+  # Value at (0,0) plus
                     min  # Minimum of
                          f(.[1..*])   # Rows 1..*
                                     f $_>>[1..*]  # Columns 1..*
                         (          ,            )||0  # Or 0 if empty
```
[Answer]
# [Röda](https://github.com/fergusq/roda), ~~100~~ 89 bytes
```
f A{g={|x,y|{g(x-1,y)if[x>0];g(x,y-1)if[y>0];[0]if[x+y=0]}|min|[A[x][y]+_]}g#A-1,#A[0]-1}
```
[Try it online!](https://tio.run/##bVLbisIwEH33KwZ9UYyQm61lcaHfEYLIaqUPtov1oaXtt3dnkuBibMoQknPmTOZ0HvXlPE0F5P3t2A8t64b@tm53gnWbsjDtN7dfeGbdTtC5o7PhlqBtd@R2HO5lNZjctNZ0dnuy422VY/YqR9ZOjNP9XFbQLwDX89o8Tz/n5trAEYy7omXwy4CBoJAMFFj2AgmmSyEYJEQQMyBlSw9iLmjO3sQp7wBeQ8biCrxw6vYITIKwy5ZOXKXv4hqhfaDouXwCszlQBtA/z4uLeXGxxzggzmONhLlQrgCRI0IaqssMg1R07F/inZcp7or2uIQKzmG21M6HSAEziUSlhHZvoF4y/d6L4L6PNHiaffihfbMyzILczxjmZkGTE@RITDh4F4gk5Vyz1IPwQT19/hPB/kmZeyT1IrhyNBvP8QBF/YCcQQOX@qX0@yirJxTrfMNgibO@RNyBl7q6LsbpDw "Röda – Try It Online")
*-9 bytes thanks to [Cows quack](https://codegolf.stackexchange.com/users/41805/cows-quack)*
[Answer]
# [Python 3](https://docs.python.org/3/), 108 bytes
```
def f(A,m,n,i=0,j=0):r=i+1<m and f(A,m,n,i+1,j);d=j+1<n and f(A,m,n,i,j+1);return A[i][j]+min(r or d,d or r)
```
[Try it online!](https://tio.run/##VVDbboMwDH3vV/itRPUqEqDXMYnvQGhCgqpBkKLAJvXrme2wG8I49jn2OWF8zveHSxY7jA8/w/ScEOppXpr2BreowAEd2jzGLo/Vxed2p18HqF3zC@40dura5B1B7j@E1FNX384f3kFR2qrsqt1gXeTh4aHBhpNXy41SAdbBUI8Rqe97O7e@7t/bz7pHNrWf5sY6ddkAPaO3biYN2L68bVHkoG9dVKg1l3GllFrKMquqDX0RTDhUCGU4nhE0vQYh4SYfNDUOnL4bxJG2DBByChzDeCLcI325OgiT8bA9RcikTlc0k21SGal43R@q5iB@EguF91GQCMPcOgY7HEyVTfoglzCE6YSzzCarS751Ko6YShxGmCorWVrHQfgo7s8yHeyYsDhb/crfSdkdu5TmSawxYMyPH57UIdhCuK4OIgKcWab6Ag "Python 3 – Try It Online")
## Ungolfed
```
def f(A, m, n, i=0, j=0):
    right = i + 1 < m and f(A, m, n, i + 1, j)
    down  = j + 1 < n and f(A, m, n, i, j + 1)
    return A[i][j] + min(right or down, down or right)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 21 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ZI_.ỊȦ
ŒJŒPÇƇLÐṀœị⁸§Ṃ
```
**[Try it online!](https://tio.run/##y0rNyan8/z/KM17v4e6uE8u4jk7yOjop4HD7sXafwxMe7mw4Ovnh7u5HjTsOLX@4s@n////R0QqWOgoKhjoKhkZA2jiWSycaxDIEiiiYgWiYCFgdWCY2FgA "Jelly – Try It Online")**
### How?
```
ZI_.ỊȦ - Link 1: isDownRight?: List of 2d indices (limited to having no repetitions)
Z      - transpose
 I     - deltas (vectorises)
  _.   - subtract 1/2 (vectorises)
    Ị  - insignificant? (effectively _.Ị here is like "v in {0,1}? 1 : 0")
     Ȧ - any & all (0 if a 0 is present when flattened, else 1)
ŒJŒPÇƇLÐṀœị⁸§Ṃ - Main Link: list of lists of integers, A
ŒJ             - multi-dimensional indices of A
  ŒP           - power-set
     Ƈ         - filter keep only those truthy by:
    Ç          -   last link as a monad
       ÐṀ      - filter keep only those maximal by:
      L        -   length
           ⁸   - chain's left argument, A
         œị    - multi-dimensional index into (vectorises)
            §  - sum each
             Ṃ - minimum
```
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), ~~37~~ 32 bytes
```
{⊃⌽,9e9(⊢⌊⍵+(2⊣⌿⍪)⌊2⊣/,)⍣≡+⍀+\⍵}
```
[Try it online!](https://tio.run/##RU/LSgNBELznK/q2MyTB7Zl9ZPwWL0s0sriQkOQiEhCUQNas6MEP0Ny85yKI/9I/slbvBoWhqa6uruopFtX48rao5tfjaVWsVuW0lee3ci7bl7idod5J/SD771G4CkbqD9nX0hyHxkl9kP2PNJ8WlHZnIyvNQXbvQ2nuhxdQbdp23Tk0R9BLwJk0X@fR/CaSp8doVpRVBALj5WZgYJXaNaWKdtqQQ5v3gz@8fTWBmNiRtwaVmTKUDgfS3kKZxL00o4kqnDUespwyC8op6VTmT44JpeASHaZwAXAAWO5E/C9ivAn5GAL4ZOQJrDW5RuNhil3GQeRyYo8Kpe9OwBcSjTWcEyiMdRX@Ien9OVZ7DClgSdOc@qR6jH40QS7S0eJUZZzr4yBkfUjRy5lOTIAR/Dn2g/Ev "APL (Dyalog Classic) – Try It Online")
`+⍀+\` partial sums horizontally and vertically - this provides an initial overestimate for the paths to each square
`9e9(`...`)⍣≡` apply "..." until convergence, at each step passing some very large number (9×109) as left argument
`,` add `9e9`-s to the left of the current estimate
`2⊣/` take the first from each pair of consecutive cells, effectively dropping the last column
`2⊣⌿⍪` same thing vertically - put `9e9` on top and drop last row
`(2⊣⌿⍪) ⌊ 2⊣/,` minima
`⍵+` add the original matrix
`⊢⌊` try to improve the current estimates with that
`⊃⌽,` bottom-right cell
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 46 bytes
```
≔Ｅ§θ⁰∧κΣ§θ⁰ηＦθ«≔§η⁰ζＦＬι«≔⁺⌊⟦§ηκζ⟧§ικζ§≔ηκζ»»Ｉζ
```
[Try it online!](https://tio.run/##VY7NCsIwEITP5in2uIEVTLSoeCqeBAXBY@ih@NdgjdpWEcVnj0lNUANLYOab2V0XebU@5aW1aV3rvcFFfsa0mZnN9o4Xgh4nSM0GDwSr6/HfcY@g4BO2O1WAFw5P1gktkSs@DQ8HdVpqvjX7pkDNWzriy/Ja40IbfXQ71E/44MOZvyFo2muxMcR/@eC82IstK20anOZ1gw/OJ9YqpUD0CERCMAQC6WYMGTEABXJAkARR@D@JhhekGwf0fXoUjRHBIJiyBYLh@6X4jBAeiglBX3PcLs8y272Vbw "Charcoal – Try It Online") Link is to verbose version of code. Explanation: This would probably be shorter if there was a three-argument `reduce` in Charcoal.
```
≔Ｅ§θ⁰∧κΣ§θ⁰η
```
Prefill the working array with large values except for the first which is zero.
```
Ｆθ«
```
Loop over the rows of the input.
```
≔§η⁰ζ
```
Initialise the current total with the first element of the working array.
```
ＦＬι«
```
Loop over the columns of the input.
```
≔⁺⌊⟦§ηκζ⟧§ικζ
```
Take the minimum of the current total and the current element of the working array and add the current element of the input to give the new current total.
```
§≔ηκζ
```
And store that back in the working array ready for the next row.
```
»»Ｉζ
```
Print the total once the input has been completely processed.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 17 bytes
```
XL,1ẋLḊŒ!1;ⱮÄịẎ§Ṃ
```
[Try it online!](https://tio.run/##y0rNyan8/z/CR8fw4a5un4c7uo5OUjS0frRx3eGWh7u7H@7qO7T84c6m////RytEK1gq6CgYgrCRjoKxQqwOlwJQEMQxNNRRMANJGCIJglQbQQQVYgE "Jelly – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~26~~ 25 bytes
```
∧≜.&{~g~g|hhX&{b|bᵐ}↰+↙X}
```
[Try it online!](https://tio.run/##RU8xasNAEPyKcOEm6@C9k05S43zDcFwRpZCKQCBNMLJcuDB2lzaQPq0bh5Df@D6izMgHgWNvd2Z2Z7d5fXzqNs8vrRn76@/penmPx6/ZYrHKZm8P8XCO@z3hn2/EAewIOp4@7@f9rt21265bz/tm24AZoL6Lh4/1MI4@874IQfiJSUkQn9JaVNSIBYJPVRzCraiFwE3mpCJpwFhISnHIHASA06RcClT5hBdoZmaQofVfoHiV2CU5tDuxAhhVSTs88GxUrCGmFLWIFNvJHhfkNISgFGAQsB211yWHA5WaepoZzphu5YlQWmgq1tiTkDHJDVrlg8e0tkqCakwLWfgD "Brachylog – Try It Online")
-1 byte because the cut isn't necessary--you can't take the head of an empty list
There's probably a lot of room to golf this but I need sleep.
The approach boils down to trying every value for the output, smallest first, (`∧≜.`) until a path can be found (`b|bᵐ`) to the bottom right corner (`~g~g`) which produces that sum (`hhX&...↰+↙X`).
[Answer]
# Java 8, ~~197~~ ~~193~~ ~~190~~ 188 bytes
```
m->{int r=m.length-1,c=m[0].length-1,i=r;for(;i-->0;)m[i][c]+=m[i+1][c];for(i=c;i-->0;)m[r][i]+=m[r][i+1];for(i=r*c;i-->0;)m[i/c][r=i%c]+=Math.min(m[i/c+1][r],m[i/c][r+1]);return m[0][0];}
```
-9 bytes thanks to *@ceilingcat*.
[Try it online.](https://tio.run/##jVRNb9swDL33VxABBtgLk1mWP2Ok9x3aDejR8MFz3VZd7ASKkqEo8tsz0nFqpWsHA4pgPT2Sj6TC53Jfzp7vfx@rVbndwk2p2tcrANWaWj@UVQ23fOwAqBza8yIvGjcj8HBF29aURlVwCy0sj83s@pWJetnMV3X7aJ5mAqtlk3vFcFZLnT2stZOp2ezay9wmV0VeFVOiqangz@5aLauBoQsiMYM/iNQz9FeLo75VRa6X6gv7uinN07xRrdPh7FYXeObQ0c10bXa6BdZGKzscM05ns/u1onT6rPZrdQ8NlcS5M1q1j3kBpXuqh6m3xmnrP9CX5IQCvAr0UWJwwDMQosAI4wFIiCFQHLrzoSvlf/yFY3noj/b4JmWsCaQIJNlHkIMxHYVAiGi/AJnMV2N9RwhJ58kf3IBkxxDTboERO2byWN0BhpjYzYgISG3AJyDCZKzWAIH6SStB6VleIqTFoplgKY65Gj4tMrGiiojr6ccoJO2WH8mFILIfcJIDP0a6Im@i8z9OrPBYKUvgnlhBQk6CQQ5lifW5wxRBkmFi8RNOi658/zIJkil4ce/skgrsr1KOO1KspH9JTNWQFMqjXC8UeBQhjVAGPqYRN8CqfURyE7KIgwgDlmg/x1DGGKXU8ZRqR5LS0HpPiRdiLOkFULWBiFJevFl7vnWToBP/NgJP0u9etqZu5uudmW9oRJhV60y@t5udWcCkz3lDo8a8/ORbp@mxj8x@7MzJbtrOK2J@Tv1Ynh3nnUoel/tSQ7k4IwO2X5RuD/0bzJnAZK7rTV0aR86c/XQycftR7rjulM54TvNzpayVf4fjXw)
**General explanation:**
I actually already did this challenge about a year ago with [Project Euler #81](https://projecteuler.net/problem=81), except that was limited to a square-matrix instead of an `N` by `M` matrix. So I slightly modified my code from back then to account for that.
I first sum the bottom row and rightmost column from the very last cell backwards. So let's use the example matrix of the challenge:
```
1, 2, 3, 4
5, 1, 6, 7
8, 2, 1, 1
```
The last cell remains the same. The second last cell of the bottom row becomes the sum: `1+1 = 2`, and the same for the second last cell of the rightmost column: `1+7 = 8`. We continue doing this, so now the matrix looks like this:
```
 1,  2,  3, 12
 5,  1,  6,  8
12,  4,  2,  1
```
After doing that, we look at all the remaining rows one by one from bottom to top and right to left (except for the last column/row), and we look for each cell at both the cell below it and right of it to see which one is smaller.
So the cell containing the number `6` becomes `8`, because the `2` below it is smaller than the `8` right of it. Then we look at the `1` next of it (to the left), and do the same. That `1` becomes `5`, because the `4` below it is smaller than the `8` right of it.
So after we're done with the second to last row, the matrix looks like this:
```
 1,  2,  3, 12
10,  5,  8,  8
12,  4,  2,  1
```
And we continue doing this for the entire matrix:
```
 8,  7, 11, 12
10,  5,  8,  8
12,  4,  2,  1
```
Now the very first cell will contain our result, which is `8` in this case.
**Code explanation:**
```
m->{                    // Method with integer-matrix input and integer return-type
  int r=m.length-1,     //  Amount of rows minus 1
      c=m[0].length-1,  //  Amount of columns minus 1
      i=r;              //  Index integer
  for(;i-->0;)m[i][c]+=m[i+1][c];
                        //  Calculate the suffix-sums for the rightmost column
  for(i=c;i-->0;)m[r][i]+=m[r][i+1];
                        //  Calculate the suffix-sums for the bottom row
  for(i=r*c;i-->0;)     //  Loop over the cells in reversed order:
    m[i/c][r=i%c]+=     //   Add to the value of the current cell:
      Math.min(         //    The minimum of:
        m[i/c+1][r],    //     The value in the cell below it
        m[i/c][r+1]);   //     And the value in the cell left of it
  return m[0][0];}      //  Return the value in the cell at index {0,0} as result
```
[Answer]
# [Java (JDK)](http://jdk.java.net/), 223 bytes
Takes input as a 2D List of ints.
Additional 19 bytes for `import java.util.*;` included.
```
import java.util.*;m->{var l=m.get(0);int s=m.size(),c=l.size(),x=-1>>>1,a=l.get(0);return s*c<2?a:Math.min(s>1?n.n(new Vector(m.subList(1,s))):x,c>1?n.n(new Vector<>(m){{replaceAll(l->new Vector(l.subList(1,c)));}}):x)+a;}
```
[Try it online!](https://tio.run/##lVVNb6MwED2HXzHiBE2CYvJdEqoe9rDSppdKvVQ9uISmdI1B2GnTjfjt2bEhlABdaS1k8MybN8/jD97oOx2@bX@fojhNMglvOHb2MmLOlWcY6f6ZRQEEjAoBGxpxOBoGYCsdQlKJr4jLMHuhQQh3CICylRh0Ard@RUKudPcTwbsw832IbU@Dc6On3yXbHXBYQzz0R55Rtx@Br09oPr7TDNg6dnahtEa2pxIIHIroT2jZg2DNzp@H9ZD4vk8GFG0lOgvlPuMgroKVe0OvN1S@OnHELeGTG@5wi4cf8BAGMskspNw/K80WGQjbtq8Pg6CFWvlWbB@PWZgyLMAtYxYb@jUSViMJkMTLcySy@9TLT17udZXzPYm2EGO1rXuZRXz3@AQ02wkb5GuWfAj4cQjCVEYJ/6q1DDGBOTXLitZM4HYYzQGYlb3hXAIQfFwYm4PKpZuJRkJghl7S5cNIV/u6iTFuodyoqBk8BsU6x77lmmlSFXgxkQb3BGCqUZMuAnQtu1yudildXdR1ZjIFsoDxqEFhujPAB@VrWNM713ndJbgY3kxvkpkqtDsHMsa@xTzWpcL1m6ipN2PngADkJxOYfi@ejJTyuS7hsiUPmafFkmE/bXn1JkD@MZIsWt6FmjICXLdraiibqAenMGnnJVAClkpVdQt8dxT0XIqj4DhOxNO9tL@2fufNQhF9wFskpZkIN3pkFYGe0bv/FDKMnWQvnRRJJcPzjGe6CLL/JacrVz1FdV7/S6S6LW6zjH5qgG/VlvMFbxB1v@G5R@DI0x@rgt5hId/JV23r9228eXu93kWlKzmIeKBMIIWOfMTxkyNSFuEegX59/1RizzpVrDJ067zMd1YbJKxQqz5W5@yVXrQWeqHRylQO3W6tMr@jy4sDq2R5xOgnu6E4vxgVhdUsJWMN/gUt/wQF@rzo@ekv "Java (JDK) – Try It Online")
---
**How it works**
```
import java.util.*;                                     // Import needed for Vector class
m->{                                                    // Lambda that takes a 2D list of integers
    var r=m.get(0);                                     // Store first row in variable
    int h=m.size(),                                     // Store number of rows
        w=r.size(),                                     // Store number of columns
        x=-1>>>1,                                       // Store int max
        a=r.get(0);                                     // Store the current cell value
    return h*w<2?a:                                     // If matrix is single cell return value
        Math.min(                                       // Otherwise return the minimum of...
            h>1?                                        // If height is more than 1
                n.n(                                    // Recursively call this function with 
                    new Vector(m.subList(1,h))):        // a new matrix, without the top row
                x,                                      // Otherwise use int max as there is no row below this
            w>1?                                        // If width is more than 1
                n.n(new Vector<>(m){{                   // Recursively call this function with a new matrix             
                    replaceAll(                         // where all columns have been replaced with 
                        l->new Vector(l.subList(1,w))   // cloned lists without the leftmost column
                    );
                }}):                                    // Otherwise use int max as there is
                x                                       // no column to the right of this
        )+a;                                            // Add the current cell value to the result before returning
}
```
[Answer]
# [Python 2](https://docs.python.org/2/), 86 bytes
```
f=lambda A:len(A)>1<len(A[0])and A[0][0]+min(f(zip(*A)[1:]),f(A[1:]))or sum(sum(A,()))
```
[Try it online!](https://tio.run/##ZY5BDoJADEX3nqLLVrugIygaNeEcxgVGiSQwEtSFXh7bEQPRzPxM8/5vp83zfrl613XFtsrr4ymHbF2dPWa0k00o9tGBcn8CK/TO6tJjga@ywWlGe1kfiAtNWUHXFm6PGk0ZIxF1TVv6OxQIehImBgKa/EJ0rHjgqNQRKxkQoBjDOcchO3YgBoZElapiIJ6AwkUPV2PoergI6f9JEjFIwrBU34Xmb2P8aTQo9iajieJUGphbd/o1Ug6LmelCoDdsvpOPRMbLCQ/mKnweFuze "Python 2 – Try It Online")
If `B` is the transpose of `A`, then the problem definition implies that `f(A)==f(B)`. 
`A[1:]` is the array `A` missing its top row. `zip(*A[1:])` is the array `A` missing its leftmost column and transposed. `sum(sum(A,()))` is the sum of all elements in `A`.
If `A` has only a single column or single row, there is only one path, so `f` returns the sum of all elements in `A`; otherwise we recurse and return the sum of `A[0][0]` + the smaller of `f` of `A` missing the top row and `f` of `A` missing the leftmost column.
]