#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int book[800][800];
int sx[4]={0,-1,1};
int sy[4]={1,0,0};
int mapp[800][800];
int maxx=-99999999;
int n,m;
void dfs(int x,int y,int ans){
if(x==n&&y==m){
if(ans>maxx)maxx=ans;
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++){
// cout <<book[i][j]<<" ";
// }
// cout <<endl;
// }
// cout <<maxx<<endl;
return;
}
for(int i=0;i<3;i++){
int tx=x+sx[i];
int ty=y+sy[i];
if(tx>n||ty>m||tx<1||ty<1)continue;
if(book[tx][ty]==0){
book[tx][ty]=1;
dfs(tx,ty,mapp[tx][ty]+ans);
book[tx][ty]=0;
}
}
}
int main(){
cin >>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >>mapp[i][j];
}
}
book[1][1]=1;
dfs(1,1,mapp[1][1]);
cout <<maxx<<endl;
return 0;
}