#include <cstdio>
using namespace std;
int map[1002][10001]={{0}},f[1002][10001]={{0}};
int main(void)
{
freopen("azshara.in","r",stdin);
freopen("azshara.out","w",stdout);
int i,j,Ln,Col,temp;
scanf("%d %d\n",&Ln,&Col);
for (j=1;j<=Col;j++)
for (i=1;i<=Ln;i++)
scanf("%d",&map[i][j]);
for (j=1;j<=Col;j++)
for (i=1;i<=Ln;i++)
{
if (map[i][j]==-1)
continue;
temp=0;
if (map[i][j-1]!=-1&&f[i][j-1]>temp)
temp=f[i][j-1];
if (map[i-1][j-1]!=-1&&f[i-1][j-1]>temp)
temp=f[i-1][j-1];
if (map[i+1][j-1]!=-1&&f[i+1][j-1]>temp)
temp=f[i+1][j-1];
f[i][j]=temp+map[i][j];
}
temp=f[1][Col];
for (i=2;i<=Ln;i++)
if (f[i][Col]>temp)
temp=f[i][Col];
printf("%d\n",temp);
fclose(stdin);
fclose(stdout);
return(0);
}