#include <bits/stdc++.h>
using namespace std;
int n, m, a[1005][1005], dp[4][1005][1005];
void get_dp() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      dp[0][i][j] = max(dp[0][i - 1][j], dp[0][i][j - 1]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      dp[1][i][j] = max(dp[1][i + 1][j], dp[1][i][j - 1]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      dp[2][i][j] = max(dp[2][i + 1][j], dp[2][i][j + 1]) + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      dp[3][i][j] = max(dp[3][i - 1][j], dp[3][i][j + 1]) + a[i][j];
}
int compute() {
  int MAX = 0;
  for (int i = 2; i <= n - 1; i++)
    for (int j = 2; j <= m - 1; j++) {
      int sum = 0, t1 = 0, t2 = 0;
      t1 =
          dp[0][i - 1][j] + dp[2][i + 1][j] + dp[1][i][j - 1] + dp[3][i][j + 1];
      t2 =
          dp[0][i][j - 1] + dp[2][i][j + 1] + dp[1][i + 1][j] + dp[3][i - 1][j];
      sum = max(t1, t2);
      if (sum > MAX) {
      }
      MAX = max(MAX, sum);
    }
  return MAX;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  memset(dp, 0, sizeof(dp));
  get_dp();
  cout << compute() << endl;
  return 0;
}
