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