#include <bits/stdc++.h>
using namespace std;
long long m[1001][1001];
long long a[1001][1001], b[1001][1001], c[1001][1001], d[1001][1001];
int main() {
  int row, col;
  while (scanf("%d %d", &row, &col) == 2 && row && col) {
    memset(m, 0, sizeof(m));
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= row; i++)
      for (int j = 1; j <= col; j++) scanf("%lld", &m[i][j]);
    long long t1 = 0, t2 = 0;
    for (int i = 1; i <= row; i++)
      for (int j = 1; j <= col; j++)
        a[i][j] = max(a[i - 1][j], a[i][j - 1]) + m[i][j];
    for (int i = row; i >= 1; i--)
      for (int j = 1; j <= col; j++)
        b[i][j] = max(b[i + 1][j], b[i][j - 1]) + m[i][j];
    for (int i = row; i >= 1; i--)
      for (int j = col; j >= 1; j--)
        c[i][j] = max(c[i + 1][j], c[i][j + 1]) + m[i][j];
    for (int i = 1; i <= row; i++)
      for (int j = col; j >= 1; j--)
        d[i][j] = max(d[i - 1][j], d[i][j + 1]) + m[i][j];
    long long ans = 0;
    for (int i = 2; i <= row - 1; i++)
      for (int j = 2; j <= col - 1; j++) {
        if (a[i - 1][j] + b[i][j - 1] + c[i + 1][j] + d[i][j + 1] > ans)
          ans = a[i - 1][j] + b[i][j - 1] + c[i + 1][j] + d[i][j + 1];
        if (d[i - 1][j] + a[i][j - 1] + b[i + 1][j] + c[i][j + 1] > ans)
          ans = d[i - 1][j] + a[i][j - 1] + b[i + 1][j] + c[i][j + 1];
      }
    printf("%lld\n", ans);
  }
  return 0;
}
