#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
int mp[MAX_N][MAX_N];
long long dp[4][MAX_N][MAX_N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> mp[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[0][i][j] = max(dp[0][i - 1][j], dp[0][i][j - 1]) + mp[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      dp[1][i][j] = max(dp[1][i + 1][j], dp[1][i][j + 1]) + mp[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      dp[2][i][j] = max(dp[2][i + 1][j], dp[2][i][j - 1]) + mp[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      dp[3][i][j] = max(dp[3][i - 1][j], dp[3][i][j + 1]) + mp[i][j];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 || i == n || j == 1 || j == m) continue;
      long long tmp =
          dp[0][i][j - 1] + dp[1][i][j + 1] + dp[2][i + 1][j] + dp[3][i - 1][j];
      ans = max(ans, tmp);
      tmp =
          dp[0][i - 1][j] + dp[1][i + 1][j] + dp[2][i][j - 1] + dp[3][i][j + 1];
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
