#include <bits/stdc++.h>
using namespace std;
long long dp[1002][1002][5];
int a[1002][1002];
int main() {
  int n, m, i, j;
  long long res = 0, road1 = 0, road2 = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      dp[i][j][1] = a[i][j] + max(dp[i - 1][j][1], dp[i][j - 1][1]);
  for (i = 1; i <= n; i++)
    for (j = m; j >= 1; j--)
      dp[i][j][2] = a[i][j] + max(dp[i - 1][j][2], dp[i][j + 1][2]);
  for (i = n; i >= 1; i--)
    for (j = 1; j <= m; j++)
      dp[i][j][3] = a[i][j] + max(dp[i + 1][j][3], dp[i][j - 1][3]);
  for (i = n; i >= 1; i--)
    for (j = m; j >= 1; j--)
      dp[i][j][4] = a[i][j] + max(dp[i + 1][j][4], dp[i][j + 1][4]);
  for (i = 2; i <= n - 1; i++)
    for (j = 2; j <= m - 1; j++) {
      road1 =
          dp[i - 1][j][1] + dp[i + 1][j][4] + dp[i][j - 1][3] + dp[i][j + 1][2];
      road2 =
          dp[i][j - 1][1] + dp[i][j + 1][4] + dp[i - 1][j][2] + dp[i + 1][j][3];
      if (res < road1) res = road1;
      if (res < road2) res = road2;
    }
  printf("%I64d", res);
  return 0;
}
