program dpqs;
const maxn=10;
fin='number.in';
fout='number.out';
var a:array[0..maxn,0..maxn]of longint;
b:array[1..maxn,1..maxn]of longint;
m,n,i,j:longint;
begin
assign(input,fin);
reset(input);
readln(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
close(input);
assign(output,fout);
rewrite(output);
for j:=2 to n do
for i:=2 to m do
begin
b[i,j]:=b[i-1,j]+a[i,j];
if b[i,j]>b[i,j-1]+a[i,j] then b[i,j]:=b[i,j-1]+a[i,j];
end;
writeln(b[m,n]);
close(output);
end.