#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 7;
int a[MAXN][MAXN];
long long int dl[MAXN][MAXN];
long long int dr[MAXN][MAXN];
long long int ul[MAXN][MAXN];
long long int ur[MAXN][MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = n; i; i--)
    for (int j = m; j; j--) {
      const int dx[] = {0, 1};
      const int dy[] = {1, 0};
      long long int& ans = dr[i][j];
      for (int k = 0; k < 2; k++) ans = max(ans, dr[i + dx[k]][j + dy[k]]);
      ans += a[i][j];
    }
  for (int i = n; i; i--)
    for (int j = 1; j <= m; j++) {
      const int dx[] = {0, 1};
      const int dy[] = {-1, 0};
      long long int& ans = dl[i][j];
      for (int k = 0; k < 2; k++) ans = max(ans, dl[i + dx[k]][j + dy[k]]);
      ans += a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      const int dx[] = {0, -1};
      const int dy[] = {-1, 0};
      long long int& ans = ul[i][j];
      for (int k = 0; k < 2; k++) ans = max(ans, ul[i + dx[k]][j + dy[k]]);
      ans += a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = m; j; j--) {
      const int dx[] = {0, -1};
      const int dy[] = {1, 0};
      long long int& ans = ur[i][j];
      for (int k = 0; k < 2; k++) ans = max(ans, ur[i + dx[k]][j + dy[k]]);
      ans += a[i][j];
    }
  long long int ans = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      ans = max(ans, ul[i - 1][j] + dr[i + 1][j] + ur[i][j + 1] + dl[i][j - 1]);
      ans = max(ans, ul[i][j - 1] + dr[i][j + 1] + ur[i - 1][j] + dl[i + 1][j]);
    }
  cout << ans << endl;
  return 0;
}
