#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long a[N][N];
long long B1[N][N];
long long B2[N][N];
long long G1[N][N];
long long G2[N][N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  long long n, m, i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      B1[i][j] = max(B1[i - 1][j], B1[i][j - 1]) + a[i][j];
  for (i = n; i >= 1; i--)
    for (j = m; j >= 1; j--)
      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++)
      G1[i][j] = max(G1[i + 1][j], G1[i][j - 1]) + a[i][j];
  for (i = 1; i <= n; i++)
    for (j = m; j >= 1; j--)
      G2[i][j] = max(G2[i - 1][j], G2[i][j + 1]) + a[i][j];
  long long t1, t2, ans = 0;
  for (i = 2; i < n; i++) {
    for (j = 2; j < m; j++) {
      t1 = B1[i - 1][j] + B2[i + 1][j] + G1[i][j - 1] + G2[i][j + 1];
      t2 = B1[i][j - 1] + B2[i][j + 1] + G1[i + 1][j] + G2[i - 1][j];
      ans = max({ans, t1, t2});
    }
  }
  cout << ans;
}
