#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,f[51][51][51][51],a[51][51];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
for(int k=1;k<=n;k++)
for(int l=1;l<=m;l++)
{
if(i!=k&&j!=l)
f[i][j][k][l]=a[i][j]+a[k][l]+max(max(f[i-1][j][k-1][l],f[i][j-1][k][l-1]),max(f[i][j-1][k-1][l],f[i-1][j][k][l-1]));
//(f[i][j-1][k][l-1],f[i-1][j][k-1][l]),max(f[i][j-1][k-1][l],f[i-1][j][k][l-1]));
}
printf("%d",f[n][m-1][n-1][m]);
return 0;
}