#include <bits/stdc++.h>
const int maxn = 1010;
long long dp1[maxn][maxn], dp2[maxn][maxn], dp3[maxn][maxn], dp4[maxn][maxn];
long long a[1010][1010];
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--) {
      dp2[i][j] = max(dp2[i - 1][j], dp2[i][j + 1]) + a[i][j];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--) {
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j + 1]) + a[i][j];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      dp4[i][j] = max(dp4[i + 1][j], dp4[i][j - 1]) + a[i][j];
    }
  }
  long long int ans = INT_MIN;
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 2; j <= m - 1; j++) {
      ans = max(ans,
                dp1[i][j - 1] + dp3[i][j + 1] + dp2[i - 1][j] + dp4[i + 1][j]);
      ans = max(ans,
                dp1[i - 1][j] + dp3[i + 1][j] + dp2[i][j + 1] + dp4[i][j - 1]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
