#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long dp[4][1010][1010];
long long arr[1010][1010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%lld", &arr[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[0][i][j] = arr[i][j] + max(dp[0][i - 1][j], dp[0][i][j - 1]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      dp[1][i][j] = arr[i][j] + max(dp[1][i][j + 1], dp[1][i + 1][j]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      dp[2][i][j] = arr[i][j] + max(dp[2][i][j - 1], dp[2][i + 1][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      dp[3][i][j] = arr[i][j] + max(dp[3][i][j + 1], dp[3][i - 1][j]);
    }
  }
  long long ans = -1;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max(ans, dp[0][i][j - 1] + dp[1][i][j + 1] + dp[2][i + 1][j] +
                         dp[3][i - 1][j]);
      ans = max(ans, dp[0][i - 1][j] + dp[1][i + 1][j] + dp[2][i][j - 1] +
                         dp[3][i][j + 1]);
    }
  }
  cout << ans << "\n";
  return 0;
}
