#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1010;
int Dp[maxn][maxn], dp[maxn][maxn], f[maxn][maxn], g[maxn][maxn];
int a[maxn][maxn];
int n, m;
int main() {
  while (~scanf("%d%d", &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));
    memset(dp, 0, sizeof(dp));
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j)
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
    for (int i = n; i >= 1; --i)
      for (int j = m; j >= 1; --j)
        Dp[i][j] = max(Dp[i + 1][j], Dp[i][j + 1]) + a[i][j];
    for (int i = n; i >= 1; --i)
      for (int j = 1; j <= m; ++j)
        f[i][j] = max(f[i + 1][j], f[i][j - 1]) + a[i][j];
    for (int i = 1; i <= n; ++i)
      for (int j = m; j >= 1; --j)
        g[i][j] = max(g[i - 1][j], g[i][j + 1]) + a[i][j];
    int Ans = 0;
    for (int i = 2; i < n; ++i)
      for (int j = 2; j < m; ++j)
        Ans = max(Ans,
                  max(dp[i - 1][j] + Dp[i + 1][j] + f[i][j - 1] + g[i][j + 1],
                      dp[i][j - 1] + Dp[i][j + 1] + f[i + 1][j] + g[i - 1][j]));
    printf("%d\n", Ans);
  }
}
