#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
using namespace std;
int n, m, ans, a[1005][1005], la[1005][1005], lb[1005][1005], ra[1005][1005],
    rb[1005][1005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      la[i][j] = max(la[i - 1][j], la[i][j - 1]) + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j > 0; j--)
      lb[i][j] = max(lb[i - 1][j], lb[i][j + 1]) + a[i][j];
  for (int i = n; i > 0; i--)
    for (int j = 1; j <= m; j++)
      ra[i][j] = max(ra[i][j - 1], ra[i + 1][j]) + a[i][j];
  for (int i = n; i > 0; i--)
    for (int j = m; j > 0; j--)
      rb[i][j] = max(rb[i + 1][j], rb[i][j + 1]) + a[i][j];
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      ans = max(ans, la[i - 1][j] + rb[i + 1][j] + lb[i][j + 1] + ra[i][j - 1]);
      ans = max(ans, la[i][j - 1] + rb[i][j + 1] + lb[i - 1][j] + ra[i + 1][j]);
    }
  cout << ans;
  return 0;
}
