#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  ;
  int m;
  cin >> m;
  ;
  vector<vector<long long> > mat(n, vector<long long>(m));
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> mat[i][j];
  vector<vector<long long> > dp1(n, vector<long long>(m, 0)),
      dp2(n, vector<long long>(m, 0)), dp3(n, vector<long long>(m, 0)),
      dp4(n, vector<long long>(m, 0));
  dp1[0][0] = mat[0][0];
  for (i = 1; i < n; i++) dp1[i][0] = mat[i][0] + dp1[i - 1][0];
  for (j = 1; j < m; j++) dp1[0][j] = mat[0][j] + dp1[0][j - 1];
  for (i = 1; i < n; i++)
    for (j = 1; j < m; j++)
      dp1[i][j] = mat[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
  dp2[n - 1][0] = mat[n - 1][0];
  for (j = 1; j < m; j++) dp2[n - 1][j] = mat[n - 1][j] + dp2[n - 1][j - 1];
  for (i = n - 2; i >= 0; i--) dp2[i][0] = mat[i][0] + dp2[i + 1][0];
  for (i = n - 2; i >= 0; i--)
    for (j = 1; j < m; j++)
      dp2[i][j] = mat[i][j] + max(dp2[i + 1][j], dp2[i][j - 1]);
  dp3[0][m - 1] = mat[0][m - 1];
  for (j = m - 2; j >= 0; j--) dp3[0][j] = mat[0][j] + dp3[0][j + 1];
  for (i = 1; i < n; i++) dp3[i][m - 1] = mat[i][m - 1] + dp3[i - 1][m - 1];
  for (i = 1; i < n; i++)
    for (j = m - 2; j >= 0; j--)
      dp3[i][j] = mat[i][j] + max(dp3[i - 1][j], dp3[i][j + 1]);
  dp4[n - 1][m - 1] = mat[n - 1][m - 1];
  for (j = m - 2; j >= 0; j--)
    dp4[n - 1][j] = mat[n - 1][j] + dp4[n - 1][j + 1];
  for (i = n - 2; i >= 0; i--)
    dp4[i][m - 1] = mat[i][m - 1] + dp4[i + 1][m - 1];
  for (i = n - 2; i >= 0; i--)
    for (j = m - 2; j >= 0; j--)
      dp4[i][j] = mat[i][j] + max(dp4[i + 1][j], dp4[i][j + 1]);
  long long ans = 0;
  for (i = 1; i < n - 1; i++)
    for (j = 1; j < m - 1; j++)
      ans = max(
          ans,
          max(dp1[i - 1][j] + dp4[i + 1][j] + dp2[i][j - 1] + dp3[i][j + 1],
              dp1[i][j - 1] + dp4[i][j + 1] + dp2[i + 1][j] + dp3[i - 1][j]));
  cout << ans << '\n';
}
