#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using mint = atcoder::modint1000000007; int main(){ int h,w; cin>>h>>w; vector> a(h,vector(w)); rep(i,h) rep(j,w) cin>>a.at(i).at(j); vector dx={-1,0,1,1,1}; vector dy={1,1,1,0,-1}; auto isok=[&](int x,int y){ return 0<=x&&x stl; ll res=0; while(isok(x1,y1)){ res+=a.at(x1).at(y1); stl.insert(x1+y1*h); x1+=dx.at(i); y1+=dy.at(i); } while(isok(x2,y2)){ if(!stl.count(x2+y2*h)){ res+=a.at(x2).at(y2); } x2+=dx.at(j); y2+=dy.at(j); } return res; }; ll ans=0; rep(ch1,h+w-1){ int x1=0,y1=0; if(ch1>=h) y1=ch1-h+1; else x1=ch1; rep(lp,2){ for(int ch2=ch1;ch2=h) y2=ch2-h+1; else x2=ch2; rep(i,5){ rep(j,5){ ans=max(ans,select(x1,y1,i,x2,y2,j)); } } } if(x1!=0) break; x1=h-1; } } cout<