#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
int t[4][1050][1050];
int n, m;
int a[1050][1050];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) scanf("%d", &a[i + 1][j + 1]);
  memset(t, 0, sizeof(t));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      t[0][i][j] = max(t[0][i - 1][j], t[0][i][j - 1]) + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      t[1][i][j] = max(t[1][i - 1][j], t[1][i][j + 1]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      t[2][i][j] = max(t[2][i + 1][j], t[2][i][j - 1]) + a[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      t[3][i][j] = max(t[3][i + 1][j], t[3][i][j + 1]) + a[i][j];
  int ans = 0;
  for (int i = 2; i <= n - 1; i++)
    for (int j = 2; j <= m - 1; j++) {
      ans = max(ans, t[0][i - 1][j] + t[3][i + 1][j] + t[2][i][j - 1] +
                         t[1][i][j + 1]);
      ans = max(ans, t[0][i][j - 1] + t[3][i][j + 1] + t[2][i + 1][j] +
                         t[1][i - 1][j]);
    }
  cout << ans << endl;
  return 0;
}
