#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[1005][1005];
int bi[1005][1005];
int ba[1005][1005];
int ai[1005][1005];
int aa[1005][1005];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &arr[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ai[i][j] = arr[i][j] + max(ai[i - 1][j], ai[i][j - 1]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      aa[i][j] = arr[i][j] + max(aa[i - 1][j], aa[i][j + 1]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      bi[i][j] = arr[i][j] + max(bi[i + 1][j], bi[i][j - 1]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      ba[i][j] = arr[i][j] + max(ba[i + 1][j], ba[i][j + 1]);
    }
  }
  int ans = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max(ans, bi[i + 1][j] + aa[i - 1][j] + ai[i][j - 1] + ba[i][j + 1]);
      ans = max(ans, bi[i][j - 1] + aa[i][j + 1] + ai[i - 1][j] + ba[i + 1][j]);
    }
  }
  printf("%d\n", ans);
}
