#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
long long n, m, a[1005][1005], dp1[1005][1005], dp2[1005][1005],
    dp3[1005][1005], dp4[1005][1005], ans;
void calc() {
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + a[i][j];
    }
  }
  for (int i = n + 1 - 1; i >= 1; i--) {
    for (int j = 1; j < m + 1; j++) {
      dp2[i][j] = max(dp2[i][j - 1], dp2[i + 1][j]) + a[i][j];
    }
  }
  for (int i = n + 1 - 1; i >= 1; i--) {
    for (int j = m + 1 - 1; j >= 1; j--) {
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j + 1]) + a[i][j];
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = m + 1 - 1; j >= 1; j--) {
      dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + a[i][j];
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) cin >> a[i][j];
  }
  calc();
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      ans = max(ans,
                dp1[i - 1][j] + dp3[i + 1][j] + dp2[i][j - 1] + dp4[i][j + 1]);
      ans = max(ans,
                dp1[i][j - 1] + dp2[i + 1][j] + dp3[i][j + 1] + dp4[i - 1][j]);
    }
  }
  cout << ans;
  return 0;
}
