#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> c(n + 2, vector<long long>(m + 2, 0));
  vector<vector<long long>> ul(n + 2, vector<long long>(m + 2, 0));
  vector<vector<long long>> ur(n + 2, vector<long long>(m + 2, 0));
  vector<vector<long long>> dl(n + 2, vector<long long>(m + 2, 0));
  vector<vector<long long>> dr(n + 2, vector<long long>(m + 2, 0));
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> c[i][j];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      ul[i][j] = c[i][j] + max(ul[i - 1][j], ul[i][j - 1]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = m; j >= 1; j--) {
      ur[i][j] = c[i][j] + max(ur[i - 1][j], ur[i][j + 1]);
    }
  }
  for (long long i = n; i >= 1; i--)
    for (long long j = 1; j <= m; j++)
      dl[i][j] = c[i][j] + max(dl[i + 1][j], dl[i][j - 1]);
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      dr[i][j] = c[i][j] + max(dr[i + 1][j], dr[i][j + 1]);
    }
  }
  long long ans = 0;
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; j < m; j++) {
      ans = max(ans,
                max(dl[i + 1][j] + ur[i - 1][j] + ul[i][j - 1] + dr[i][j + 1],
                    dl[i][j - 1] + ur[i][j + 1] + ul[i - 1][j] + dr[i + 1][j]));
    }
  }
  cout << ans;
  return 0;
}
