#include <bits/stdc++.h>
using namespace std;
long long ar[1007][1007], boy1[1007][1007], boy2[1007][1007], girl1[1007][1007],
    girl2[1007][1007];
int main() {
  int n, m, i, j;
  cin >> n >> m;
  long long ans = 0, res = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> ar[i][j];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      boy1[i][j] = max(boy1[i - 1][j], boy1[i][j - 1]) + ar[i][j];
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = 1; j <= m; j++) {
      girl1[i][j] = max(girl1[i + 1][j], girl1[i][j - 1]) + ar[i][j];
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = m; j >= 1; j--) {
      boy2[i][j] = max(boy2[i + 1][j], boy2[i][j + 1]) + ar[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = m; j >= 1; j--) {
      girl2[i][j] = max(girl2[i - 1][j], girl2[i][j + 1]) + ar[i][j];
    }
  }
  for (i = 2; i < n; i++) {
    for (j = 2; j < m; j++) {
      ans = max(
          boy1[i - 1][j] + boy2[i + 1][j] + girl1[i][j - 1] + girl2[i][j + 1],
          boy1[i][j - 1] + boy2[i][j + 1] + girl1[i + 1][j] + girl2[i - 1][j]);
      res = max(res, ans);
    }
  }
  cout << res << endl;
  return 0;
}
