#include <bits/stdc++.h>
using namespace std;
int dp[1002][1002][4];
int grid[1001][1001];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> grid[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j][0] = grid[i][j] + max(dp[i - 1][j][0], dp[i][j - 1][0]);
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      dp[i][j][1] = grid[i][j] + max(dp[i][j - 1][1], dp[i + 1][j][1]);
    }
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--) {
      dp[i][j][2] = grid[i][j] + max(dp[i][j + 1][2], dp[i + 1][j][2]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--) {
      dp[i][j][3] = grid[i][j] + max(dp[i - 1][j][3], dp[i][j + 1][3]);
    }
  }
  int ans = -1e9;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max({ans,
                 dp[i][j - 1][0] + dp[i + 1][j][1] + dp[i][j + 1][2] +
                     dp[i - 1][j][3],
                 dp[i - 1][j][0] + dp[i][j - 1][1] + dp[i + 1][j][2] +
                     dp[i][j + 1][3]});
    }
  }
  cout << ans;
}
