#include <cstdio>
const int maxn=1005;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1},dy[]={1,0,0};
int s[maxn][maxn];
bool vis[maxn][maxn];
long long ans=-INF;
int n,m;
bool f=true;
bool is_valid(int x,int y){
if(x<1||x>n||y<1||y>m) return false;
return true;
}
void dfs(const int x[],const int y[],int len){
if(x[len]==n&&y[len]==m){
long long sum=0;
for(int i=1;i<=len;i++) sum+=s[x[i]][y[i]];
if(sum>ans) ans=sum;
return;
}
for(int RP=0;RP<3;RP++){
int tx=x[len]+dx[RP];
int ty=y[len]+dy[RP];
if(is_valid(tx,ty)){
if(!vis[tx][ty]){
//printf("x = %d\ny = %d\n\n",tx,ty);
vis[tx][ty]=true;
int newx[maxn],newy[maxn];
for(int i=1;i<=len;i++) newx[i]=x[i],newy[i]=y[i];
newx[len+1]=tx;
newy[len+1]=ty;
dfs(newx,newy,len+1);
}
}
}
}
int main(){
//freopen("ex.in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&s[i][j]);
vis[i][j]=false;
}
}
int x[maxn],y[maxn];
x[1]=1,y[1]=1;
vis[1][1]=true;
dfs(x,y,1);
printf("%lld\n",ans);
return 0;
}
连样例都没过,dalao求调 qwq