#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, A[2003][2003], dp[2003][2003],
    dp1[2003][2003], dp2[2003][2003];
long long dp3[2003][2003], ans;
string s;
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> A[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = A[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j <= m; j++) {
      dp1[i][j] = A[i][j] + max(dp1[i + 1][j], dp1[i][j - 1]);
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      dp2[i][j] = A[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = m; j >= 1; j--) {
      dp3[i][j] = A[i][j] + max(dp3[i - 1][j], dp3[i][j + 1]);
    }
  }
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; j < m; j++) {
      ans = max(ans,
                dp[i][j - 1] + dp2[i][j + 1] + dp1[i + 1][j] + dp3[i - 1][j]);
      ans = max(ans,
                dp[i - 1][j] + dp2[i + 1][j] + dp1[i][j - 1] + dp3[i][j + 1]);
    }
  }
  cout << ans;
}
