#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const long double pi = acos(-1.0);
int n;
int m;
typedef long long matrix[1010][1010];
matrix a, f, fu, fl, g, gd, gl, q, qu, qr, w, wd, wr;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      a[i][j] = x;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      fu[i][j] = f[i - 1][j] + a[i][j];
      fl[i][j] = f[i][j - 1] + a[i][j];
      f[i][j] = max(f[i - 1][j], f[i][j - 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++) {
      gd[i][j] = g[i + 1][j] + a[i][j];
      gl[i][j] = g[i][j - 1] + a[i][j];
      g[i][j] = max(g[i + 1][j], g[i][j - 1]) + a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--) {
      qu[i][j] = q[i - 1][j] + a[i][j];
      qr[i][j] = q[i][j + 1] + a[i][j];
      q[i][j] = max(q[i - 1][j], q[i][j + 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      wd[i][j] = w[i + 1][j] + a[i][j];
      wr[i][j] = w[i][j + 1] + a[i][j];
      w[i][j] = max(w[i + 1][j], w[i][j + 1]) + a[i][j];
    }
  long long ans = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      ans = max(ans, max((fl[i][j] + gd[i][j] + qu[i][j] + wr[i][j]),
                         fu[i][j] + gl[i][j] + qr[i][j] + wd[i][j]) -
                         4 * a[i][j]);
    }
  cout << ans << endl;
  return 0;
}
