#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  int n, m;
  cin >> n >> m;
  vector<vector<long long> > a(n, vector<long long>(m)),
      d_11(n, vector<long long>(m)), d_n1(n, vector<long long>(m)),
      d_1m(n, vector<long long>(m)), d_nm(n, vector<long long>(m));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  d_11[0][0] = a[0][0];
  for (i = 1; i < m; i++) d_11[0][i] = d_11[0][i - 1] + a[0][i];
  for (i = 1; i < n; i++) d_11[i][0] = d_11[i - 1][0] + a[i][0];
  for (i = 1; i < n; i++)
    for (j = 1; j < m; j++)
      d_11[i][j] = max(d_11[i - 1][j], d_11[i][j - 1]) + a[i][j];
  d_n1[n - 1][0] = a[n - 1][0];
  for (i = 1; i < m; i++) d_n1[n - 1][i] = d_n1[n - 1][i - 1] + a[n - 1][i];
  for (i = n - 2; i >= 0; i--) d_n1[i][0] = d_n1[i + 1][0] + a[i][0];
  for (i = n - 2; i >= 0; i--)
    for (j = 1; j < m; j++)
      d_n1[i][j] = max(d_n1[i + 1][j], d_n1[i][j - 1]) + a[i][j];
  d_1m[0][m - 1] = a[0][m - 1];
  for (i = m - 2; i >= 0; i--) d_1m[0][i] = d_1m[0][i + 1] + a[0][i];
  for (i = 1; i < n; i++) d_1m[i][m - 1] = d_1m[i - 1][m - 1] + a[i][m - 1];
  for (i = 1; i < n; i++)
    for (j = m - 2; j >= 0; j--)
      d_1m[i][j] = max(d_1m[i - 1][j], d_1m[i][j + 1]) + a[i][j];
  d_nm[n - 1][m - 1] = a[n - 1][m - 1];
  for (i = n - 2; i >= 0; i--)
    d_nm[i][m - 1] = d_nm[i + 1][m - 1] + a[i][m - 1];
  for (i = m - 2; i >= 0; i--)
    d_nm[n - 1][i] = d_nm[n - 1][i + 1] + a[n - 1][i];
  for (i = n - 2; i >= 0; i--)
    for (j = m - 2; j >= 0; j--)
      d_nm[i][j] = max(d_nm[i + 1][j], d_nm[i][j + 1]) + a[i][j];
  long long ans = -1;
  for (i = 1; i < n - 1; i++) {
    for (j = 1; j < m - 1; j++) {
      long long v1 = d_11[i - 1][j] + d_n1[i][j - 1] + d_1m[i][j + 1] +
                     d_nm[i + 1][j],
                v2 = d_11[i][j - 1] + d_n1[i + 1][j] + d_1m[i - 1][j] +
                     d_nm[i][j + 1];
      if (max(v1, v2) > ans) ans = max(v1, v2);
    }
  }
  cout << ans << endl;
}
