#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long> > a =
      vector<vector<long long> >(n, vector<long long>(m, 0));
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) cin >> a[i][j];
  vector<vector<long long> > rt, rb, lb, lt;
  rt = rb = lb = lt = vector<vector<long long> >(n, vector<long long>(m, 0));
  lt[0][0] = a[0][0];
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      if (!(i == 0 && j == 0))
        lt[i][j] = max((i > 0) ? lt[i - 1][j] : 0, (j > 0) ? lt[i][j - 1] : 0) +
                   a[i][j];
  rt[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 && j == m - 1))
        rt[i][j] =
            max((i > 0) ? rt[i - 1][j] : 0, (j < m - 1) ? rt[i][j + 1] : 0) +
            a[i][j];
  lb[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 && j == 0))
        lb[i][j] =
            max((i < n - 1) ? lb[i + 1][j] : 0, (j > 0) ? lb[i][j - 1] : 0) +
            a[i][j];
  rb[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 && j == m - 1))
        rb[i][j] = max((i < n - 1) ? rb[i + 1][j] : 0,
                       (j < m - 1) ? rb[i][j + 1] : 0) +
                   a[i][j];
  long long res = 0;
  for (int i = (1); i < (n - 1); ++i)
    for (int j = (1); j < (m - 1); ++j) {
      long long x = 0, y = 0;
      if (i > 0) {
        x += rt[i - 1][j];
        y += lt[i - 1][j];
      }
      if (j < m - 1) {
        x += rb[i][j + 1];
        y += rt[i][j + 1];
      }
      if (i < n - 1) {
        x += lb[i + 1][j];
        y += rb[i + 1][j];
      }
      if (j > 0) {
        x += lt[i][j - 1];
        y += lb[i][j - 1];
      }
      res = max(res, max(x, y));
    }
  cout << res;
}
