#include <bits/stdc++.h>
using namespace std;
int n, m, a[1010][1010];
int fromTopLeft[1010][1010], fromBottomLeft[1010][1010], toTopRight[1010][1010],
    toBottomRight[1010][1010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      fromTopLeft[i][j] =
          a[i][j] + max(fromTopLeft[i - 1][j], fromTopLeft[i][j - 1]);
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++)
      fromBottomLeft[i][j] =
          a[i][j] + max(fromBottomLeft[i + 1][j], fromBottomLeft[i][j - 1]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--)
      toTopRight[i][j] =
          a[i][j] + max(toTopRight[i - 1][j], toTopRight[i][j + 1]);
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--)
      toBottomRight[i][j] =
          a[i][j] + max(toBottomRight[i + 1][j], toBottomRight[i][j + 1]);
  }
  int ans = 0;
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 2; j <= m - 1; j++) {
      ans = max(ans, fromTopLeft[i - 1][j] + toBottomRight[i + 1][j] +
                         fromBottomLeft[i][j - 1] + toTopRight[i][j + 1]);
      ans = max(ans, fromTopLeft[i][j - 1] + toBottomRight[i][j + 1] +
                         fromBottomLeft[i + 1][j] + toTopRight[i - 1][j]);
    }
  }
  printf("%d", ans);
}
