#include <bits/stdc++.h>
using namespace std;
long long dp1[1100][1100];
long long dp2[1100][1100];
long long dp3[1100][1100];
long long dp4[1100][1100];
long long arr[1100][1100];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp1, 0, sizeof(dp1));
  memset(dp2, 0, sizeof(dp2));
  memset(dp3, 0, sizeof(dp3));
  memset(dp4, 0, sizeof(dp4));
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) cin >> arr[i][j];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++)
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + arr[i][j];
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j <= m; j++)
      dp2[i][j] = max(dp2[i + 1][j], dp2[i][j - 1]) + arr[i][j];
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--)
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j + 1]) + arr[i][j];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = m; j >= 1; j--)
      dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + arr[i][j];
  }
  long long ans = INT_MIN;
  for (long long i = 2; i < n; i++) {
    for (long long j = 2; j < m; j++) {
      long long aa =
          dp1[i - 1][j] + dp3[i + 1][j] + dp2[i][j - 1] + dp4[i][j + 1];
      long long bb =
          dp1[i][j - 1] + dp3[i][j + 1] + dp2[i + 1][j] + dp4[i - 1][j];
      ans = max(ans, max(aa, bb));
    }
  }
  cout << ans;
  return 0;
}
