#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 2000, MOD = 1e9 + 7;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
long long dp1[MAX][MAX], dp2[MAX][MAX], dp3[MAX][MAX], dp4[MAX][MAX],
    a[MAX][MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  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 = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + a[i][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--)
      dp2[i][j] = max(dp2[i - 1][j], dp2[i][j + 1]) + a[i][j];
  }
  for (int i = n; i > 0; i--) {
    for (int j = m; j > 0; j--)
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j + 1]) + a[i][j];
  }
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++)
      dp4[i][j] = max(dp4[i + 1][j], dp4[i][j - 1]) + a[i][j];
  }
  long long x = 0;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      x = max(x, dp1[i - 1][j] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i][j - 1]);
      x = max(x, dp1[i][j - 1] + dp2[i - 1][j] + dp3[i][j + 1] + dp4[i + 1][j]);
    }
  }
  cout << x;
  return 0;
}
