program cch(input,output);
var
i,j,l,w,ans:longint;
data:array[1..1000] of longint;
f,g:array[1..1000] of longint;
begin
assign(input,'azshara.in');
assign(output,'azshara.out');
reset(input);
rewrite(output);
readln(w,l);
for i:=1 to w do read(data[i]);
for i:=1 to w do
f[i]:=data[i];
for i:=2 to l do
begin
for j:=1 to w do g[j]:=f[j];
for j:=1 to w do read(data[j]);
for j:=1 to w do
if data[j]<>-1 then
begin
f[j]:=0;
if (g[j]<>-1)and(g[j]>f[j]) then f[j]:=g[j];
if (j-1>=1)and(g[j-1]<>-1)and(g[j-1]>f[j]) then
f[j]:=g[j-1];
if (j+1<=w)and(g[j+1]<>-1)and(g[j+1]>f[j]) then
f[j]:=g[j+1];
inc(f[j],data[j]);
end
else f[j]:=-1;
end;
ans:=0;
for i:=1 to w do
if ans<f[i] then ans:=f[i];
write(ans);
close(input);
close(output);
end.