import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main
{
{
String[] params1
= bufferedReader.
readLine().
split(" "); int n
= Integer.
parseInt(params1
[0]); int m
= Integer.
parseInt(params1
[1]); int[][] A = new int[n][m];
for (int i=0; i<n; i++) {
String[] params2
= bufferedReader.
readLine().
split(" "); for (int j=0; j<m; j++) {
A
[i
][j
] = Integer.
parseInt(params2
[j
]); }
}
for (int i=1; i<n; i++) {
A[i][0]+=A[i-1][0];
}
for (int i=1; i<m; i++) {
A[0][i]+=A[0][i-1];
}
for (int i=1; i<n; i++) {
for (int j=1; j<m; j++) {
A
[i
][j
]+=Math.
min(A
[i
-1][j
],A
[i
][j
-1]); }
}
System.
out.
println(A
[n
-1][m
-1]); }
}
aW1wb3J0IGphdmEuaW8uQnVmZmVyZWRSZWFkZXI7CmltcG9ydCBqYXZhLmlvLklucHV0U3RyZWFtUmVhZGVyOwoKY2xhc3MgTWFpbgp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIEV4Y2VwdGlvbgoJewoJCUJ1ZmZlcmVkUmVhZGVyIGJ1ZmZlcmVkUmVhZGVyID0gbmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBJbnB1dFN0cmVhbVJlYWRlcihTeXN0ZW0uaW4pKTsKCQlTdHJpbmdbXSBwYXJhbXMxID0gYnVmZmVyZWRSZWFkZXIucmVhZExpbmUoKS5zcGxpdCgiICIpOwoJCWludCBuID0gSW50ZWdlci5wYXJzZUludChwYXJhbXMxWzBdKTsKCQlpbnQgbSA9IEludGVnZXIucGFyc2VJbnQocGFyYW1zMVsxXSk7CgkJaW50W11bXSBBID0gbmV3IGludFtuXVttXTsKCQlmb3IgKGludCBpPTA7IGk8bjsgaSsrKQl7CgkgICAgICAgIFN0cmluZ1tdIHBhcmFtczIgPSBidWZmZXJlZFJlYWRlci5yZWFkTGluZSgpLnNwbGl0KCIgIik7CgkJCWZvciAoaW50IGo9MDsgajxtOyBq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