#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > arr(n, vector<int>(m));
  vector<vector<int> > tl(n, vector<int>(m));
  vector<vector<int> > tr(n, vector<int>(m));
  vector<vector<int> > bl(n, vector<int>(m));
  vector<vector<int> > br(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0)
        tl[i][j] = arr[i][j];
      else if (i == 0)
        tl[i][j] = arr[i][j] + tl[i][j - 1];
      else if (j == 0)
        tl[i][j] = arr[i][j] + tl[i - 1][j];
      else
        tl[i][j] = max(arr[i][j] + tl[i - 1][j], arr[i][j] + tl[i][j - 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j > -1; j--) {
      if (i == 0 && j == m - 1)
        tr[i][j] = arr[i][j];
      else if (i == 0)
        tr[i][j] = arr[i][j] + tr[i][j + 1];
      else if (j == m - 1)
        tr[i][j] = arr[i][j] + tr[i - 1][j];
      else
        tr[i][j] = max(arr[i][j] + tr[i - 1][j], arr[i][j] + tr[i][j + 1]);
    }
  }
  for (int i = n - 1; i > -1; i--) {
    for (int j = 0; j < m; j++) {
      if (i == n - 1 && j == 0)
        bl[i][j] = arr[i][j];
      else if (i == n - 1)
        bl[i][j] = arr[i][j] + bl[i][j - 1];
      else if (j == 0)
        bl[i][j] = arr[i][j] + bl[i + 1][j];
      else
        bl[i][j] = max(arr[i][j] + bl[i + 1][j], arr[i][j] + bl[i][j - 1]);
    }
  }
  for (int i = n - 1; i > -1; i--) {
    for (int j = m - 1; j > -1; j--) {
      if (i == n - 1 && j == m - 1)
        br[i][j] = arr[i][j];
      else if (i == n - 1)
        br[i][j] = arr[i][j] + br[i][j + 1];
      else if (j == m - 1)
        br[i][j] = arr[i][j] + br[i + 1][j];
      else
        br[i][j] = max(arr[i][j] + br[i + 1][j], arr[i][j] + br[i][j + 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      ans = max(ans, tl[i - 1][j] + br[i + 1][j] + tr[i][j + 1] + bl[i][j - 1]);
      ans = max(ans, tl[i][j - 1] + br[i][j + 1] + tr[i - 1][j] + bl[i + 1][j]);
    }
  }
  cout << ans << endl;
}
