#include <bits/stdc++.h>
using namespace std;
int dp[4][1020][1020];
int a[1020][1020];
int main() {
  int n, m, i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  k = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      dp[k][i][j] = a[i][j] + max(dp[k][i - 1][j], dp[k][i][j - 1]);
    }
  k = 1;
  for (i = n; i >= 1; i--)
    for (j = m; j >= 1; j--) {
      dp[k][i][j] = a[i][j] + max(dp[k][i + 1][j], dp[k][i][j + 1]);
    }
  k = 2;
  for (i = n; i >= 1; i--)
    for (j = 1; j <= m; j++) {
      dp[k][i][j] = a[i][j] + max(dp[k][i + 1][j], dp[k][i][j - 1]);
    }
  k = 3;
  for (i = 1; i <= n; i++)
    for (j = m; j >= 1; j--) {
      dp[k][i][j] = a[i][j] + max(dp[k][i - 1][j], dp[k][i][j + 1]);
    }
  int ans = 0, temp;
  for (i = 2; i < n; i++)
    for (j = 2; j < m; j++) {
      temp =
          dp[0][i - 1][j] + dp[1][i + 1][j] + dp[2][i][j - 1] + dp[3][i][j + 1];
      ans = max(ans, temp);
      temp =
          dp[3][i - 1][j] + dp[2][i + 1][j] + dp[0][i][j - 1] + dp[1][i][j + 1];
      ans = max(ans, temp);
    }
  printf("%d\n", ans);
  return 0;
}
