#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 10;
const int maxn5 = 5 * 1000 * 100 + 10;
const int maxn3 = 1000 + 10;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long inf = 1LL * 2 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;
long long dpad[maxn3][maxn3], dpcb[maxn3][maxn3], dpda[maxn3][maxn3],
    dpbc[maxn3][maxn3], a[maxn3][maxn3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  dpad[0][0] = a[0][0];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (i == 0 and j == 0) continue;
      if (i > 0) dpad[i][j] = dpad[i - 1][j];
      if (j > 0) dpad[i][j] = max(dpad[i][j], dpad[i][j - 1]);
      dpad[i][j] += a[i][j];
    }
  dpcb[n - 1][0] = a[n - 1][0];
  for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < m; j++) {
      if (i == n - 1 and j == 0) continue;
      if (i < n - 1) dpcb[i][j] = dpcb[i + 1][j];
      if (j > 0) dpcb[i][j] = max(dpcb[i][j], dpcb[i][j - 1]);
      dpcb[i][j] += a[i][j];
    }
  dpda[n - 1][m - 1] = a[n - 1][m - 1];
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--) {
      if (i == n - 1 and j == m - 1) continue;
      if (i < n - 1) dpda[i][j] = dpda[i + 1][j];
      if (j < m - 1) dpda[i][j] = max(dpda[i][j], dpda[i][j + 1]);
      dpda[i][j] += a[i][j];
    }
  dpbc[0][m - 1] = a[0][m - 1];
  for (int i = 0; i < n; i++)
    for (int j = m - 1; j >= 0; j--) {
      if (i == 0 and j == m - 1) continue;
      if (i > 0) dpbc[i][j] = dpbc[i - 1][j];
      if (j < m - 1) dpbc[i][j] = max(dpbc[i][j], dpbc[i][j + 1]);
      dpbc[i][j] += a[i][j];
    }
  long long ans = 0;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      long long b =
          dpad[i][j - 1] + dpda[i][j + 1] + dpcb[i + 1][j] + dpbc[i - 1][j];
      b = max(
          b, dpad[i - 1][j] + dpda[i + 1][j] + dpcb[i][j - 1] + dpbc[i][j + 1]);
      ans = max(ans, b);
    }
  cout << ans << endl;
  return 0;
}
