#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int nmax = 100005;
const long long inf = 1e9;
const double eps = 1e-6;
long long dp[1005][1005];
long long gp[1005][1005];
long long a[1005][1005];
long long rdp[1005][1005];
long long rgp[1005][1005];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
    }
  }
  for (int i = n; i; --i) {
    for (int j = m; j; --j) {
      rdp[i][j] = max(rdp[i][j + 1], rdp[i + 1][j]) + a[i][j];
    }
  }
  for (int i = n; i; --i) {
    for (int j = 1; j <= m; ++j) {
      gp[i][j] = max(gp[i + 1][j], gp[i][j - 1]) + a[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = m; j; --j) {
      rgp[i][j] = max(rgp[i - 1][j], rgp[i][j + 1]) + a[i][j];
    }
  }
  long long ans = 0;
  for (int i = 2; i < n; ++i) {
    for (int j = 2; j < m; ++j) {
      ans =
          max(ans, dp[i][j - 1] + rdp[i][j + 1] + gp[i + 1][j] + rgp[i - 1][j]);
      ans =
          max(ans, dp[i - 1][j] + rdp[i + 1][j] + gp[i][j - 1] + rgp[i][j + 1]);
    }
  }
  cout << ans << '\n';
  return 0;
}
