program azshara;
var
n,m,ans:longint;
f:array[0..1,0..10001] of longint;
procedure init;
var
i,j,num,k,d:longint;
begin
readln(m,n);
f[0][0]:=-1; f[0][m+1]:=-1;
f[1][0]:=-1; f[1][m+1]:=-1;
for i:=1 to n do
begin
k:=i mod 2;
for j:=1 to m do
begin
read(num);
if num=-1 then f[k][j]:=-1
else
for d:=-1 to 1 do
if f[1-k][j+d]<>-1
then if f[1-k][j+d]+num>f[k][j]
then f[k][j]:=f[1-k][j+d]+num;
end;
end;
end;
procedure print;
var
i:longint;
begin
if n mod 2=0
then begin
for i:=1 to m do
if f[0][i]>ans then ans:=f[0][i]
end
else
for i:=1 to m do
if f[1][i]>ans then ans:=f[1][i];
writeln(ans);
end;
begin
assign(input,'azshara.in');
assign(output,'azshara.out');
reset(input); rewrite(output);
init;
print;
close(input); close(output);
end.