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