#include <bits/stdc++.h>
using namespace std;
long long a[1005][1005];
long long dp[4][1005][1005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      dp[0][i][j] = a[i][j] + max(i > 0 ? dp[0][i - 1][j] : 0,
                                  j > 0 ? dp[0][i][j - 1] : 0);
  for (int i = n - 1; i > -1; --i)
    for (int j = m - 1; j > -1; --j)
      dp[1][i][j] = a[i][j] + max(i + 1 < n ? dp[1][i + 1][j] : 0,
                                  j + 1 < m ? dp[1][i][j + 1] : 0);
  for (int i = n - 1; i > -1; --i)
    for (int j = 0; j < m; ++j)
      dp[2][i][j] = a[i][j] + max(i + 1 < n ? dp[2][i + 1][j] : 0,
                                  j > 0 ? dp[2][i][j - 1] : 0);
  for (int i = 0; i < n; ++i)
    for (int j = m - 1; j > -1; --j)
      dp[3][i][j] = a[i][j] + max(i > 0 ? dp[3][i - 1][j] : 0,
                                  j + 1 < m ? dp[3][i][j + 1] : 0);
  long long ans = 0;
  for (int i = 1; i < n - 1; ++i)
    for (int j = 1; j < m - 1; ++j) {
      ans = max(ans, dp[0][i - 1][j] + dp[1][i + 1][j] + dp[2][i][j - 1] +
                         dp[3][i][j + 1]);
      ans = max(ans, dp[0][i][j - 1] + dp[1][i][j + 1] + dp[2][i + 1][j] +
                         dp[3][i - 1][j]);
    }
  cout << ans;
  return 0;
}
