#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long a[N][N], dp[N][N][4];
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  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][0] = max(dp[i - 1][j][0], dp[i][j - 1][0]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      dp[i][j][1] = max(dp[i + 1][j][1], dp[i][j + 1][1]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      dp[i][j][2] = max(dp[i + 1][j][2], dp[i][j - 1][2]) + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      dp[i][j][3] = max(dp[i - 1][j][3], dp[i][j + 1][3]) + a[i][j];
  long long ans = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      long long sum = 0;
      sum =
          dp[i][j - 1][0] + dp[i + 1][j][2] + dp[i][j + 1][1] + dp[i - 1][j][3];
      sum = max(sum, dp[i - 1][j][0] + dp[i][j - 1][2] + dp[i + 1][j][1] +
                         dp[i][j + 1][3]);
      ans = max(ans, sum);
    }
  }
  cout << ans;
  return 0;
}
