#include <bits/stdc++.h>
using namespace std;
long long n, m, l, i, j, r, k, a[1111][1111], t, x, y, kol, ans, s;
long long dp1[1111][1111], dp2[1111][1111], dp3[1111][1111], dp4[1111][1111];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  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 >= 1; i--)
    for (j = 1; j <= m; j++)
      dp2[i][j] = max(dp2[i + 1][j], dp2[i][j - 1]) + a[i][j];
  for (i = n; i >= 1; i--)
    for (j = m; j >= 1; 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 >= 1; 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++)
      ans = max(
          ans,
          max(dp1[i][j - 1] + dp3[i][j + 1] + dp4[i - 1][j] + dp2[i + 1][j],
              dp1[i - 1][j] + dp3[i + 1][j] + dp4[i][j + 1] + dp2[i][j - 1]));
  cout << ans;
  return 0;
}
