#include <bits/stdc++.h>
using namespace std;
static long long m1[1001][1001], m2[1001][1001], m3[1001][1001], m4[1001][1001],
    m5[1001][1001];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> m1[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (i > 0 && j > 0)
        m2[i][j] = max(m2[i][j - 1], m2[i - 1][j]) + m1[i][j];
      else if (i > 0)
        m2[i][j] = m2[i - 1][j] + m1[i][j];
      else if (j > 0)
        m2[i][j] = m2[i][j - 1] + m1[i][j];
      else
        m2[i][j] = m1[i][j];
    }
  for (int i = 0; i < n; ++i)
    for (int j = m - 1; j >= 0; --j) {
      if (i > 0 && j < m - 1)
        m3[i][j] = max(m3[i][j + 1], m3[i - 1][j]) + m1[i][j];
      else if (i > 0)
        m3[i][j] = m3[i - 1][j] + m1[i][j];
      else if (j < m - 1)
        m3[i][j] = m3[i][j + 1] + m1[i][j];
      else
        m3[i][j] = m1[i][j];
    }
  for (int i = n - 1; i >= 0; --i)
    for (int j = 0; j < m; ++j) {
      if (i < n - 1 && j > 0)
        m4[i][j] = max(m4[i][j - 1], m4[i + 1][j]) + m1[i][j];
      else if (i < n - 1)
        m4[i][j] = m4[i + 1][j] + m1[i][j];
      else if (j > 0)
        m4[i][j] = m4[i][j - 1] + m1[i][j];
      else
        m4[i][j] = m1[i][j];
    }
  for (int i = n - 1; i >= 0; --i)
    for (int j = m - 1; j >= 0; --j) {
      if (i < n - 1 && j < m - 1)
        m5[i][j] = max(m5[i][j + 1], m5[i + 1][j]) + m1[i][j];
      else if (i < n - 1)
        m5[i][j] = m5[i + 1][j] + m1[i][j];
      else if (j < m - 1)
        m5[i][j] = m5[i][j + 1] + m1[i][j];
      else
        m5[i][j] = m1[i][j];
    }
  long long res = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (i && j && i < n - 1 && j < m - 1) {
        res =
            max(res, m2[i - 1][j] + m3[i][j + 1] + m5[i + 1][j] + m4[i][j - 1]);
        res =
            max(res, m2[i][j - 1] + m3[i - 1][j] + m5[i][j + 1] + m4[i + 1][j]);
      }
  cout << res << endl;
  return 0;
}
