#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e3 + 9;
long long n, m, mat[N][N], dp1[N][N], dp2[N][N], dp3[N][N], dp4[N][N], ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%lld", &mat[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp1[i][j] = mat[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--) {
      dp2[i][j] = mat[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]);
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      dp3[i][j] = mat[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--) {
      dp4[i][j] = mat[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i != 1 and j != m and i != n and j != 1 and
          max(dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j],
              dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]) >
              ans) {
        ans =
            max(dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j],
                dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
