#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int n, m, mat[MAXN][MAXN];
int dp1[MAXN][MAXN], dp2[MAXN][MAXN], dp3[MAXN][MAXN], dp4[MAXN][MAXN];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &mat[i][j]);
      dp1[i][j] = mat[i][j];
      dp2[i][j] = mat[i][j];
      dp3[i][j] = mat[i][j];
      dp4[i][j] = mat[i][j];
    }
  for (int i = 1; i < n; i++) {
    dp1[i][0] += dp1[i - 1][0];
    dp2[n - i - 1][m - 1] += dp2[n - i][m - 1];
    dp3[n - i - 1][0] += dp3[n - i][0];
    dp4[i][m - 1] += dp4[i - 1][m - 1];
  }
  for (int i = 1; i < m; i++) {
    dp1[0][i] += dp1[0][i - 1];
    dp2[n - 1][m - i - 1] += dp2[n - 1][m - i];
    dp3[n - 1][i] += dp3[n - 1][i - 1];
    dp4[0][m - i - 1] += dp4[0][m - i];
  }
  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]);
  for (int i = n - 2; i >= 0; i--)
    for (int j = m - 2; j >= 0; j--)
      dp2[i][j] += max(dp2[i + 1][j], dp2[i][j + 1]);
  for (int i = n - 2; i >= 0; i--)
    for (int j = 1; j < m; j++) dp3[i][j] += max(dp3[i + 1][j], dp3[i][j - 1]);
  for (int i = 1; i < n; i++)
    for (int j = m - 2; j >= 0; j--)
      dp4[i][j] += max(dp4[i - 1][j], dp4[i][j + 1]);
  int r = -1;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      int pos1 = dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j];
      int pos2 = dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1];
      int pos = max(pos1, pos2);
      if (pos > r) {
        r = max(r, pos);
      }
    }
  printf("%d\n", r);
  return 0;
}
