#include <bits/stdc++.h>
using namespace std;
int nhang, ncot;
int v1[1111][1111];
int v2[1111][1111];
int v3[1111][1111];
int v4[1111][1111];
int s[1111][1111];
int kq;
void input() {
  int n;
  int i, j;
  for (i = 1; i <= nhang; i++) {
    for (j = 1; j <= ncot; j++) {
      scanf("%d", &s[i][j]);
    }
  }
}
void solve() {
  int i, j;
  memset(v1, 0, sizeof(v1));
  memset(v2, 0, sizeof(v2));
  memset(v3, 0, sizeof(v3));
  memset(v4, 0, sizeof(v4));
  for (i = 1; i <= nhang; i++)
    for (j = 1; j <= ncot; j++)
      v1[i][j] = max(v1[i - 1][j], v1[i][j - 1]) + s[i][j];
  for (i = nhang; i > 0; i--)
    for (j = 1; j <= ncot; j++)
      v2[i][j] = max(v2[i + 1][j], v2[i][j - 1]) + s[i][j];
  for (i = 1; i <= nhang; i++)
    for (j = ncot; j > 0; j--)
      v3[i][j] = max(v3[i - 1][j], v3[i][j + 1]) + s[i][j];
  for (i = nhang; i > 0; i--)
    for (j = ncot; j > 0; j--)
      v4[i][j] = max(v4[i + 1][j], v4[i][j + 1]) + s[i][j];
  kq = -1;
  for (i = 2; i < nhang; i++) {
    for (j = 2; j < ncot; j++) {
      kq = max(kq, v1[i][j - 1] + v2[i + 1][j] + v3[i - 1][j] + v4[i][j + 1]);
      kq = max(kq, v1[i - 1][j] + v2[i][j - 1] + v3[i][j + 1] + v4[i + 1][j]);
    }
  }
  printf("%d\n", kq);
}
int main() {
  while (scanf("%d %d", &nhang, &ncot) > 0) {
    input();
    solve();
  }
  return 0;
}
