#include using namespace std; int main() { int H, W; cin >> H >> W; vector x = {1, 0, 1, 1}; vector y = {0, 1, 1, -1}; vector> s(4); vector> A(H, vector(W)); for( int i = 0; i < H; i++ ) { for( int j = 0; j < W; j++ ) { cin >> A[i][j]; for( int k = 0; k < 4; k++ ) { s[k][x[k]*i+y[k]*j] += A[i][j]; } } } long long ans = 0; for( int i = -1000; i <= 1000; i++ ) { for( int j = -1000; j <= 1000; j++ ) { for( int k = 0; k < 4; k++ ) { for( int l = 0; l < 4; l++ ) { if( k == l ) continue; if( 0 <= i && i < H && 0 <= j && j < W ) ans = max(ans, s[k][x[k]*i+y[k]*j]+s[l][x[l]*i+y[l]*j]-A[i][j]); else ans = max(ans, s[k][x[k]*i+y[k]*j]+s[l][x[l]*i+y[l]*j]); } } } } for( int i = 0; i < 4; i++ ) { vector v = {0}; for( auto [j, k] : s[i] ) v.push_back(k); sort(v.rbegin(), v.rend()); ans = max(ans, v[0]+v[1]); } cout << ans << endl; }