#include <bits/stdc++.h>
using namespace std;
int M[1002][1002];
long long pdAT[1002][1002], pdBT[1002][1002], pdAB[1002][1002],
    pdBB[1002][1002];
int n, m;
long long solveA(int r, int c) {
  if (r > n || c > m) return 0;
  if (pdAT[r][c] != -1) return pdAT[r][c];
  return pdAT[r][c] = max(solveA(r + 1, c), solveA(r, c + 1)) + M[r][c];
}
long long solveB(int r, int c) {
  if (r < 1 || c > m) return 0;
  if (pdBT[r][c] != -1) return pdBT[r][c];
  return pdBT[r][c] = max(solveB(r - 1, c), solveB(r, c + 1)) + M[r][c];
}
int main(void) {
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> M[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      pdAB[i][j] = max(pdAB[i - 1][j], pdAB[i][j - 1]) + M[i][j];
  for (i = n; i > 0; i--)
    for (j = 1; j <= m; j++)
      pdBB[i][j] = max(pdBB[i + 1][j], pdBB[i][j - 1]) + M[i][j];
  memset(pdAT, -1, sizeof pdAT);
  memset(pdBT, -1, sizeof pdBT);
  solveA(1, 1);
  solveB(n, 1);
  long long ans = 0;
  for (i = 2; i < n; i++) {
    for (j = 2; j < m; j++) {
      ans = max(ans, pdAB[i - 1][j] + pdAT[i + 1][j] + pdBB[i][j - 1] +
                         pdBT[i][j + 1]);
      ans = max(ans, pdAB[i][j - 1] + pdAT[i][j + 1] + pdBB[i + 1][j] +
                         pdBT[i - 1][j]);
    }
  }
  cout << ans << endl;
}
