#include <bits/stdc++.h>
using namespace std;
int m, n;
long long f[5][1010][1010], a[1010][1010];
int main() {
  std::ios::sync_with_stdio(false);
  cin >> m >> n;
  for (int i = (1); i <= m; i++)
    for (int j = (1); j <= n; j++) cin >> a[i][j];
  for (int i = (1); i <= m; i++)
    for (int j = (1); j <= n; j++)
      f[1][i][j] = max(f[1][i - 1][j], f[1][i][j - 1]) + a[i][j];
  for (int i = (m); i >= (1); i--)
    for (int j = (1); j <= n; j++)
      f[2][i][j] = max(f[2][i + 1][j], f[2][i][j - 1]) + a[i][j];
  for (int i = (1); i <= m; i++)
    for (int j = (n); j >= (1); j--)
      f[3][i][j] = max(f[3][i - 1][j], f[3][i][j + 1]) + a[i][j];
  for (int i = (m); i >= (1); i--)
    for (int j = (n); j >= (1); j--)
      f[4][i][j] = max(f[4][i + 1][j], f[4][i][j + 1]) + a[i][j];
  long long res = 0;
  for (int i = (2); i <= m - 1; i++)
    for (int j = (2); j <= n - 1; j++) {
      res = max(res, f[1][i - 1][j] + f[2][i][j - 1] + f[3][i][j + 1] +
                         f[4][i + 1][j]);
      res = max(res, f[1][i][j - 1] + f[2][i + 1][j] + f[3][i - 1][j] +
                         f[4][i][j + 1]);
    }
  cout << res << endl;
  return 0;
}
