#include <bits/stdc++.h>
using namespace std;
int a[1010][1010], n, m, tl[1010][1010], tr[1010][1010], dl[1010][1010],
    dr[1010][1010];
void chkmax(int &a, int b) {
  if (a < b) a = b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.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++) {
      tl[i][j] = max(tl[i - 1][j], tl[i][j - 1]) + a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--) {
      tr[i][j] = max(tr[i - 1][j], tr[i][j + 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++) {
      dl[i][j] = max(dl[i + 1][j], dl[i][j - 1]) + a[i][j];
    }
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      dr[i][j] = max(dr[i + 1][j], dr[i][j + 1]) + a[i][j];
    }
  int ans = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      chkmax(ans, tl[i - 1][j] + dr[i + 1][j] + dl[i][j - 1] + tr[i][j + 1]);
      chkmax(ans, tl[i][j - 1] + dr[i][j + 1] + dl[i + 1][j] + tr[i - 1][j]);
    }
  cout << ans;
  return 0;
}
