#include <bits/stdc++.h>
using namespace std;
const int nax = 1e3 + 5;
int dp[nax][nax][4];
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1][m + 1];
  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++)
      dp[i][j][0] = max(dp[i - 1][j][0], dp[i][j - 1][0]) + a[i][j];
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--)
      dp[i][j][3] = max(dp[i + 1][j][3], dp[i][j + 1][3]) + a[i][j];
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++)
      dp[i][j][1] = max(dp[i + 1][j][1], dp[i][j - 1][1]) + a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--)
      dp[i][j][2] = max(dp[i - 1][j][2], dp[i][j + 1][2]) + a[i][j];
  }
  int sol = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      sol = max(sol, dp[i - 1][j][0] + dp[i][j - 1][1] + dp[i][j + 1][2] +
                         dp[i + 1][j][3]);
      sol = max(sol, dp[i][j - 1][0] + dp[i + 1][j][1] + dp[i - 1][j][2] +
                         dp[i][j + 1][3]);
    }
  }
  cout << sol << endl;
  return 0;
}
