#include <bits/stdc++.h>
using namespace std;
int A[1003][1003], M11[1003][1003], M1n[1003][1003], Mm1[1003][1003],
    Mmn[1003][1003], m, n, i, j, t, mx;
int main() {
  cin >> m >> n;
  for (i = 1; i <= m; i++)
    for (j = 1; j <= n; j++) {
      cin >> A[i][j];
      M11[i][j] = max(M11[i - 1][j], M11[i][j - 1]) + A[i][j];
    }
  for (i = 1; i <= m; i++)
    for (j = n; j; j--) M1n[i][j] = max(M1n[i - 1][j], M1n[i][j + 1]) + A[i][j];
  for (i = m; i; i--)
    for (j = 1; j <= n; j++)
      Mm1[i][j] = max(Mm1[i + 1][j], Mm1[i][j - 1]) + A[i][j];
  for (i = m; i; i--)
    for (j = n; j; j--) {
      Mmn[i][j] = max(Mmn[i + 1][j], Mmn[i][j + 1]) + A[i][j];
      if (i != 1 && i != m && j != 1 && j != n)
        mx = max(
            mx,
            max(M11[i][j - 1] + Mmn[i][j + 1] + Mm1[i + 1][j] + M1n[i - 1][j],
                M11[i - 1][j] + Mmn[i + 1][j] + Mm1[i][j - 1] + M1n[i][j + 1]));
    }
  cout << mx;
  return 0;
}
