#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int w,l;
int save[10010][1010];
//inline long long mks(long long a,long long b,long long c) {return c>(a>b?a:b)?c:(a>b?a:b);}
inline int mks(int a,int b,int c) {return c>(a>b?a:b)?c:(a>b?a:b);}
int main()
{
freopen("azshara.in","r",stdin);
freopen("azshara.out","w",stdout);
cin>>w>>l;
for(int i=1;i<=l;i++)
for(int j=1;j<=w;j++)
cin>>save[i][j];
for(int i=l-1;i>=0;i--){
for(int j=1;j<=w;j++){
if(save[i][j]==-1) {save[i][j]=-1;continue;}
save[i][j]+=mks(save[i+1][j-1],save[i+1][j],save[i+1][j+1]);
}
}
int ansu=0;
for(int i=1;i<=w;i++) ansu=max(ansu,save[1][i]);
cout<<ansu<<endl;
return 0;
}