#include <bits/stdc++.h>
using namespace std;
const int MAX = 1011;
const int INF = 1e9;
const double EPS = 1e-9;
int lu[MAX][MAX], ru[MAX][MAX], ld[MAX][MAX], rd[MAX][MAX];
int inp[MAX][MAX];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> inp[i][j];
  lu[n - 1][0] = inp[n - 1][0];
  ru[n - 1][m - 1] = inp[n - 1][m - 1];
  ld[0][0] = inp[0][0];
  rd[0][m - 1] = inp[0][m - 1];
  for (int i = 1; i < n; ++i) {
    lu[n - 1 - i][0] = lu[n - i][0] + inp[n - 1 - i][0];
    ru[n - 1 - i][m - 1] = ru[n - i][m - 1] + inp[n - 1 - i][m - 1];
    ld[i][0] = ld[i - 1][0] + inp[i][0];
    rd[i][m - 1] = rd[i - 1][m - 1] + inp[i][m - 1];
  }
  for (int i = 1; i < m; ++i) {
    lu[n - 1][i] = lu[n - 1][i - 1] + inp[n - 1][i];
    ru[n - 1][m - 1 - i] = ru[n - 1][m - i] + inp[n - 1][m - 1 - i];
    ld[0][i] = ld[0][i - 1] + inp[0][i];
    rd[0][m - 1 - i] = rd[0][m - i] + inp[0][m - 1 - i];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      lu[n - 1 - i][j] =
          max(lu[n - i][j], lu[n - i - 1][j - 1]) + inp[n - 1 - i][j];
      ru[n - 1 - i][m - 1 - j] =
          max(ru[n - i][m - 1 - j], ru[n - 1 - i][m - j]) +
          inp[n - 1 - i][m - 1 - j];
      ld[i][j] = max(ld[i - 1][j], ld[i][j - 1]) + inp[i][j];
      rd[i][m - 1 - j] =
          max(rd[i - 1][m - 1 - j], rd[i][m - j]) + inp[i][m - 1 - j];
    }
  }
  int mx = 0;
  for (int i = 1; i < n - 1; ++i) {
    for (int j = 1; j < m - 1; ++j) {
      mx = max(lu[i + 1][j] + ld[i][j - 1] + ru[i][j + 1] + rd[i - 1][j], mx);
      mx = max(lu[i][j - 1] + ld[i - 1][j] + ru[i + 1][j] + rd[i][j + 1], mx);
    }
  }
  cout << mx << '\n';
  return 0;
}
