#include <bits/stdc++.h>
using namespace std;
int const maxn = 1100;
int a[maxn][maxn];
long long dp[5][maxn][maxn];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        dp[1][i][j] = max(dp[1][i - 1][j], dp[1][i][j - 1]) + a[i][j];
      }
      for (int j = m; j >= 1; j--) {
        dp[4][i][j] = max(dp[4][i - 1][j], dp[4][i][j + 1]) + a[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]) + a[i][j];
      }
      for (int j = m; j >= 1; j--) {
        dp[3][i][j] = max(dp[3][i + 1][j], dp[3][i][j + 1]) + a[i][j];
      }
    }
    long long ans = 0;
    for (int i = 2; i < n; i++) {
      for (int j = 2; j < m; j++) {
        long long num1 = (dp[1][i - 1][j] + dp[3][i + 1][j]) +
                         (dp[2][i][j - 1] + dp[4][i][j + 1]);
        ans = max(ans, num1);
        long long num2 = (dp[1][i][j - 1] + dp[3][i][j + 1]) +
                         (dp[2][i + 1][j] + dp[4][i - 1][j]);
        ans = max(ans, num2);
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
