#include <bits/stdc++.h>
using namespace std;
int n, m, a[1005][1005];
long long s[1005][1005][4], ans;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s[i][j][0] = max(s[i - 1][j][0], s[i][j - 1][0]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      s[i][j][1] = max(s[i + 1][j][1], s[i][j - 1][1]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      s[i][j][2] = max(s[i + 1][j][2], s[i][j + 1][2]) + a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      s[i][j][3] = max(s[i - 1][j][3], s[i][j + 1][3]) + a[i][j];
    }
  }
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max(ans, s[i][j - 1][0] + s[i - 1][j][3] + s[i][j + 1][2] +
                         s[i + 1][j][1]);
      ans = max(ans, s[i][j - 1][1] + s[i - 1][j][0] + s[i][j + 1][3] +
                         s[i + 1][j][2]);
    }
  }
  cout << ans << endl;
  return 0;
}
