#include <bits/stdc++.h>
using namespace std;
const int MAX = 1010;
int n, m;
int A[MAX][MAX];
long long dp[5][MAX][MAX];
void Input() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> A[i][j];
  }
}
void Process() {
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      dp[1][i][j] = A[i][j] + max(dp[1][i - 1][j], dp[1][i][j - 1]);
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--)
      dp[2][i][j] = A[i][j] + max(dp[2][i + 1][j], dp[2][i][j + 1]);
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++)
      dp[3][i][j] = A[i][j] + max(dp[3][i + 1][j], dp[3][i][j - 1]);
  }
  for (int j = m; j >= 1; j--) {
    for (int i = 1; i <= n; i++)
      dp[4][i][j] = A[i][j] + max(dp[4][i - 1][j], dp[4][i][j + 1]);
  }
  long long ans = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max(ans, dp[1][i][j - 1] + dp[2][i][j + 1] + dp[3][i + 1][j] +
                         dp[4][i - 1][j]);
      ans = max(ans, dp[1][i - 1][j] + dp[2][i + 1][j] + dp[3][i][j - 1] +
                         dp[4][i][j + 1]);
    }
  }
  cout << ans;
}
void Output() { Process(); }
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Input();
  Output();
  return 0;
}
