#include <bits/stdc++.h>
using namespace std;
const int N = 1010, MOD = 1e9 + 7;
int a[N][N];
int dp1[N][N][2], dp2[N][N][2];
int main() {
  int n, m;
  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++) {
      dp1[i][j][0] = max(dp1[i - 1][j][0], dp1[i][j - 1][0]) + a[i][j];
    }
  }
  for (int i = n; i; i--) {
    for (int j = m; j; j--) {
      dp1[i][j][1] = max(dp1[i + 1][j][1], dp1[i][j + 1][1]) + a[i][j];
    }
  }
  for (int i = n; i; i--) {
    for (int j = 1; j <= m; j++) {
      dp2[i][j][0] = max(dp2[i + 1][j][0], dp2[i][j - 1][0]) + a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j; j--) {
      dp2[i][j][1] = max(dp2[i - 1][j][1], dp2[i][j + 1][1]) + a[i][j];
    }
  }
  int ans = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      int t1 = dp1[i - 1][j][0] + dp1[i + 1][j][1] + dp2[i][j - 1][0] +
               dp2[i][j + 1][1];
      int t2 = dp2[i + 1][j][0] + dp2[i - 1][j][1] + dp1[i][j - 1][0] +
               dp1[i][j + 1][1];
      ans = max(ans, max(t1, t2));
    }
  }
  cout << ans << endl;
  return 0;
}
