#include <bits/stdc++.h>
using namespace std;
long long DR[1002][1002];
long long DL[1002][1002];
long long UL[1002][1002];
long long UR[1002][1002];
long long A[1002][1002];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> A[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      DR[i][j] = A[i][j] + max(DR[i - 1][j], DR[i][j - 1]);
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      UR[i][j] = A[i][j] + max(UR[i - 1][j], UR[i][j + 1]);
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      DL[i][j] = A[i][j] + max(DL[i + 1][j], DL[i][j - 1]);
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      UL[i][j] = A[i][j] + max(UL[i + 1][j], UL[i][j + 1]);
  long long ats = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      ats = max(ats, DR[i][j - 1] + UL[i][j + 1] + DL[i + 1][j] + UR[i - 1][j]);
      ats = max(ats, DR[i - 1][j] + UL[i + 1][j] + DL[i][j - 1] + UR[i][j + 1]);
    }
  cout << ats;
}
