#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &m, &n);
  long long int a[m + 1][n + 1];
  long long int dp1[m + 2][n + 2], dp2[m + 2][n + 2], dp3[m + 2][n + 2],
      dp4[m + 2][n + 2];
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  memset(dp3, 0, sizeof(dp3));
  memset(dp4, 0, sizeof(dp4));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      dp1[i][j] = a[i][j] + max(dp1[i][j - 1], dp1[i - 1][j]);
  for (int i = m; i >= 1; i--)
    for (int j = n; j >= 1; j--)
      dp2[i][j] = a[i][j] + max(dp2[i][j + 1], dp2[i + 1][j]);
  for (int i = m; i >= 1; i--)
    for (int j = 1; j <= n; j++)
      dp3[i][j] = a[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]);
  for (int i = 1; i <= m; i++)
    for (int j = n; j >= 1; j--)
      dp4[i][j] = a[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]);
  long long int maxi = -1;
  for (int i = 2; i < m; i++)
    for (int j = 2; j < n; j++) {
      maxi = max(maxi,
                 dp3[i + 1][j] + dp4[i - 1][j] + dp1[i][j - 1] + dp2[i][j + 1]);
      maxi = max(maxi,
                 dp3[i][j - 1] + dp4[i][j + 1] + dp1[i - 1][j] + dp2[i + 1][j]);
    }
  cout << maxi << endl;
}
