#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 5;
long long A[maxn][maxn], dp[2][maxn][maxn], pd[2][maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      cin >> A[i][j];
      dp[0][i][j] = A[i][j];
      dp[0][i][j] += max(dp[0][i - 1][j], dp[0][i][j - 1]);
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = m; j > 0; j--) {
      pd[1][i][j] = A[i][j];
      pd[1][i][j] += max(pd[1][i - 1][j], pd[1][i][j + 1]);
    }
  for (long long i = n; i > 0; i--)
    for (long long j = 1; j <= m; j++) {
      pd[0][i][j] = A[i][j];
      pd[0][i][j] += max(pd[0][i + 1][j], pd[0][i][j - 1]);
    }
  for (long long i = n; i > 0; i--)
    for (long long j = m; j > 0; j--) {
      dp[1][i][j] = A[i][j];
      dp[1][i][j] += max(dp[1][i + 1][j], dp[1][i][j + 1]);
    }
  long long ans = 0;
  for (long long i = 2; i < n; i++)
    for (long long j = 2; j < m; j++) {
      long long now = 0, now2 = 0;
      now += (pd[0][i][j - 1] + dp[1][i + 1][j] + pd[1][i][j + 1] +
              dp[0][i - 1][j]);
      now2 += (dp[0][i][j - 1] + pd[0][i + 1][j] + dp[1][i][j + 1] +
               pd[1][i - 1][j]);
      ans = max(ans, max(now, now2));
    }
  cout << ans;
  return 0;
}
