#include <bits/stdc++.h>
using namespace std;
long long dp1[1005][1005], dp2[1005][1005], dp3[1005][1005], dp4[1005][1005],
    ans;
int Map[1005][1005], n, m;
void Ans() {
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  memset(dp3, 0, sizeof(dp3));
  memset(dp4, 0, sizeof(dp4));
  int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      dp1[i][j] = Map[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = m; j >= 1; j--) {
      dp2[i][j] = Map[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = m; j >= 1; j--) {
      dp3[i][j] = Map[i][j] + max(dp3[i - 1][j], dp3[i][j + 1]);
    }
  }
  for (i = n; i >= 1; i--) {
    for (j = 1; j <= m; j++) {
      dp4[i][j] = Map[i][j] + max(dp4[i + 1][j], dp4[i][j - 1]);
    }
  }
}
int main() {
  int i, j;
  while (scanf("%d%d", &n, &m) != EOF) {
    ans = 0;
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) scanf("%d", &Map[i][j]);
    Ans();
    for (i = 2; i < n; i++) {
      for (j = 2; j < m; j++) {
        ans = max(
            ans, dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j + 1] + dp4[i][j - 1]);
        ans = max(
            ans, dp1[i][j - 1] + dp2[i][j + 1] + dp3[i - 1][j] + dp4[i + 1][j]);
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
