#include <bits/stdc++.h>
using namespace std;
long long dp[4][1005][1005];
long long g[1005][1005];
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++) cin >> g[i][j];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[0][i][j] = max(dp[0][i - 1][j], dp[0][i][j - 1]) + g[i][j];
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j <= m; j++)
      dp[1][i][j] = max(dp[1][i][j - 1], dp[1][i + 1][j]) + g[i][j];
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      dp[2][i][j] = max(dp[2][i + 1][j], dp[2][i][j + 1]) + g[i][j];
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = m; j >= 1; j--)
      dp[3][i][j] = max(dp[3][i - 1][j], dp[3][i][j + 1]) + g[i][j];
  }
  long long mx = 0;
  for (long long i = 2; i <= n - 1; i++) {
    for (long long j = 2; j <= m - 1; j++) {
      long long ans1 =
          dp[0][i - 1][j] + dp[1][i][j - 1] + dp[2][i + 1][j] + dp[3][i][j + 1];
      long long ans2 =
          dp[0][i][j - 1] + dp[1][i + 1][j] + dp[2][i][j + 1] + dp[3][i - 1][j];
      ans1 = max(ans1, ans2);
      mx = max(mx, ans1);
    }
  }
  cout << mx << endl;
  return 0;
}
