#include <bits/stdc++.h>
using namespace std;
long long tbl[1010][1010];
long long lp1[1010][1010], lp2[1010][1010], lp3[1010][1010], lp4[1010][1010];
int main() {
  int n, i, j, k, m;
  while (cin >> n >> m) {
    for (i = 0; i <= n + 2; i++)
      for (j = 0; j <= m + 2; j++)
        lp1[i][j] = lp2[i][j] = lp3[i][j] = lp4[i][j] = 0;
    int tmp;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        scanf(" %d", &tmp);
        tbl[i][j] = (long long)tmp;
        lp1[i][j] = max(lp1[i - 1][j], lp1[i][j - 1]) + tbl[i][j];
      }
      for (j = m; j >= 1; j--)
        lp4[i][j] = max(lp4[i - 1][j], lp4[i][j + 1]) + tbl[i][j];
    }
    for (i = n; i >= 1; i--) {
      for (j = 1; j <= m; j++)
        lp2[i][j] = max(lp2[i + 1][j], lp2[i][j - 1]) + tbl[i][j];
      for (j = m; j >= 1; j--)
        lp3[i][j] = max(lp3[i + 1][j], lp3[i][j + 1]) + tbl[i][j];
    }
    long long ans = 0, cura, curb, cur1, cur2;
    for (i = 2; i < n; i++)
      for (j = 2; j < m; j++) {
        cura = lp1[i][j - 1] + lp2[i + 1][j];
        curb = lp1[i - 1][j] + lp2[i][j - 1];
        cur1 = lp3[i + 1][j] + lp4[i][j + 1];
        cur2 = lp3[i][j + 1] + lp4[i - 1][j];
        ans = max(ans, max(cura + cur2, curb + cur1));
      }
    cout << ans << endl;
  }
}
