#include <bits/stdc++.h>
using namespace std;
const long long sz = 1e3 + 10;
long long mat[sz][sz], dp1[sz][sz], dp2[sz][sz], dp3[sz][sz], dp4[sz][sz];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j) scanf("%lld", &mat[i][j]);
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j)
      dp1[i][j] = mat[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] = mat[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]);
  for (long long i = n; i >= 1; --i)
    for (long long j = 1; j <= m; ++j)
      dp3[i][j] = mat[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]);
  for (long long i = 1; i <= n; ++i)
    for (long long j = m; j >= 1; --j)
      dp4[i][j] = mat[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]);
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      if (i + 1 <= n && i - 1 >= 1 && j + 1 <= m && j - 1 >= 1) {
        ans = max(
            ans, dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]);
        ans = max(
            ans, dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
