#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, T, c = 0;
int a[1010][1010] = {0}, b1[1010][1010] = {0}, c1[1010][1010] = {0},
    b2[1010][1010] = {0}, c2[1010][1010] = {0};
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  b1[1][1] = a[1][1];
  c1[1][m] = a[1][m];
  b2[n][m] = a[n][m];
  c2[n][1] = a[n][1];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (i == 1 and j == 1) {
      } else {
        b1[i][j] = max(b1[i - 1][j], b1[i][j - 1]) + a[i][j];
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = m; j >= 1; j--) {
      if (i == 1 and j == m) {
      } else {
        c1[i][j] = max(c1[i - 1][j], c1[i][j + 1]) + a[i][j];
      }
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = m; j >= 1; j--) {
      if (i == n and j == m) {
      } else {
        b2[i][j] = max(b2[i + 1][j], b2[i][j + 1]) + a[i][j];
      }
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = 1; j <= m; j++) {
      if (i == n and j == 1) {
      } else {
        c2[i][j] = max(c2[i + 1][j], c2[i][j - 1]) + a[i][j];
      }
    }
  }
  for (i = 2; i <= n - 1; i++) {
    for (j = 2; j <= m - 1; j++) {
      c = max(c, b1[i - 1][j] + b2[i + 1][j] + c1[i][j + 1] + c2[i][j - 1]);
      c = max(c, b1[i][j - 1] + b2[i][j + 1] + c1[i - 1][j] + c2[i + 1][j]);
    }
  }
  cout << c;
}
