#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1001;
vector<vector<int> > d;
vector<vector<int> > k(MaxN, vector<int>(MaxN, -1));
vector<vector<int> > l(MaxN, vector<int>(MaxN, -1));
vector<vector<int> > c(MaxN, vector<int>(MaxN, -1));
vector<vector<int> > x(MaxN, vector<int>(MaxN, -1));
const int INF = 100000;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    vector<int> a;
    for (int j = 0; j < m; j++) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    d.push_back(a);
  }
  k[0][0] = d[0][0];
  c[n - 1][m - 1] = d[n - 1][m - 1];
  x[n - 1][0] = d[n - 1][0];
  l[0][m - 1] = d[0][m - 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i > 0) {
        k[i][j] = max(k[i - 1][j] + d[i][j], k[i][j]);
      }
      if (j > 0) {
        k[i][j] = max(k[i][j - 1] + d[i][j], k[i][j]);
      }
    }
  }
  for (int i = n - 1; i > 0; i--) {
    for (int j = m - 1; j > 0; j--) {
      if (i < n - 1) {
        c[i][j] = max(c[i + 1][j] + d[i][j], c[i][j]);
      }
      if (j < m - 1) {
        c[i][j] = max(c[i][j + 1] + d[i][j], c[i][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j > 0; j--) {
      if (i > 0) {
        l[i][j] = max(l[i - 1][j] + d[i][j], l[i][j]);
      }
      if (j < m - 1) {
        l[i][j] = max(l[i][j + 1] + d[i][j], l[i][j]);
      }
    }
  }
  for (int i = n - 1; i > 0; i--) {
    for (int j = 0; j < m; j++) {
      if (i < n - 1) {
        x[i][j] = max(x[i + 1][j] + d[i][j], x[i][j]);
      }
      if (j > 0) {
        x[i][j] = max(x[i][j - 1] + d[i][j], x[i][j]);
      }
    }
  }
  int U = -1;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      U = max(k[i][j - 1] + l[i - 1][j] + c[i][j + 1] + x[i + 1][j], U);
      U = max(k[i - 1][j] + l[i][j + 1] + c[i + 1][j] + x[i][j - 1], U);
    }
  }
  cout << U;
  return 0;
}
