#include <bits/stdc++.h>
using namespace std;
int n, m;
long long arr[1005][1005];
long long a[1005][1005];
long long b[1005][1005];
long long c[1005][1005];
long long d[1005][1005];
int main() {
  int i = 0, j = 0, cs = 0, in;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) cin >> arr[i][j];
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      a[i][j] = max(a[i - 1][j], a[i][j - 1]) + arr[i][j];
  }
  for (i = n; i > 0; i--) {
    for (j = m; j > 0; j--) b[i][j] = max(b[i + 1][j], b[i][j + 1]) + arr[i][j];
  }
  for (i = n; i > 0; i--) {
    for (j = 1; j <= m; j++)
      c[i][j] = max(c[i + 1][j], c[i][j - 1]) + arr[i][j];
  }
  for (i = 1; i <= n; i++) {
    for (j = m; j > 0; j--) d[i][j] = max(d[i - 1][j], d[i][j + 1]) + arr[i][j];
  }
  long long ans = 0;
  for (i = 2; i < n; i++) {
    for (j = 2; j < m; j++) {
      long long x = a[i - 1][j] + b[i + 1][j] + c[i][j - 1] + d[i][j + 1];
      x = max(x, a[i][j - 1] + b[i][j + 1] + c[i + 1][j] + d[i - 1][j]);
      ans = max(ans, x);
    }
  }
  cout << ans << "\n";
  return 0;
}
