#include<cstdio>
#include<algorithm>
#include<iostream>
#define fuck(x) cerr << #x << " <- " << x << endl
using namespace std;
const int maxn=555;
int val[maxn][maxn],sum[maxn][maxn],figure[maxn][maxn];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&val[i][j]);
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+val[i][j];
        }
    }
    int cmp,ans;
    ans=-(1<<30);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            figure[i][j]=val[i][j];
            for(int sz=1;i+sz<=n&&i-sz>=1&&j+sz<=m&&j-sz>=1;sz++)
            {
                int square=sum[i+sz][j+sz]-sum[i+sz][j-sz-1]-sum[i-sz-1][j+sz]+sum[i-sz-1][j-sz-1];

                int cmp=square-figure[i][j]-val[i-sz+1][j-sz];
                figure[i][j]=cmp;
                ans=max(cmp,ans);
//                if(i==4&&j==3)fuck(cmp),fuck(square);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}
