#include <bits/stdc++.h>
using namespace std;
const int maxNM = 1000 + 3;
int n, m;
int a[maxNM][maxNM];
long long f[4][maxNM][maxNM];
void enter() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
}
void Suzy() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      f[0][i][j] = max(f[0][i - 1][j], f[0][i][j - 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      f[1][i][j] = max(f[1][i + 1][j], f[1][i][j + 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++) {
      f[2][i][j] = max(f[2][i + 1][j], f[2][i][j - 1]) + a[i][j];
    }
  for (int j = m; j >= 1; j--)
    for (int i = 1; i <= n; i++) {
      f[3][i][j] = max(f[3][i - 1][j], f[3][i][j + 1]) + a[i][j];
    }
}
void solve() {
  long long res = 0;
  for (int i = 2; i <= n - 1; i++)
    for (int j = 2; j <= m - 1; j++) {
      res = max(res, f[0][i - 1][j] + f[1][i + 1][j] + f[2][i][j - 1] +
                         f[3][i][j + 1]);
      res = max(res, f[0][i][j - 1] + f[1][i][j + 1] + f[2][i + 1][j] +
                         f[3][i - 1][j]);
    }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  enter();
  Suzy();
  solve();
  return 0;
}
