#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a[1005][1005], dp1[1005][1005], dp2[1005][1005],
    dp3[1005][1005], dp4[1005][1005], rs = -1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) cin >> a[i][j];
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j)
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + a[i][j];
  for (i = n; i; --i)
    for (j = m; j; --j) dp2[i][j] = max(dp2[i + 1][j], dp2[i][j + 1]) + a[i][j];
  for (i = n; i; --i)
    for (j = 1; j <= m; ++j)
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + a[i][j];
  for (i = 1; i <= n; ++i)
    for (j = m; j; --j) dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + a[i][j];
  for (i = 2; i < n; ++i)
    for (j = 2; j < m; ++j)
      rs = max(
          rs,
          max(dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j],
              dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]));
  cout << rs << '\n';
  return 0;
}
