#include<bits/stdc++.h>
using namespace std;
int maze[1005][1005];
int n,m,ans=-1e6;
int f[1005][1005];
int dfs(int x,int y){
if(f[x][y]!=0x7f7f7f7f){
return f[x][y];
}
if(x<1 || y<1 || y>m){
return 0;
}
int a=dfs(x-1,y);
int b=dfs(x-1,y-1);
int c=dfs(x-1,y+1);
f[x][y]=max(max(a,b),c)+maze[x][y];
return f[x][y];
}
int main(){
cin>>n>>m;
memset(f,0x7f,sizeof f);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>maze[i][j];
}
}
cout<<dfs(n+1,m/2+1);
return 0;
}