#include <bits/stdc++.h>
using namespace std;
template <typename c>
void smax(c &x, c y) {
  x = max(x, y);
}
template <typename c>
void smin(c &x, c y) {
  x = min(x, y);
}
const long long maxn = 1e3 + 11;
long long mp[maxn][maxn], dr[maxn][maxn], dl[maxn][maxn], ur[maxn][maxn],
    ul[maxn][maxn], n, m, ans;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> mp[i][j];
  dr[n - 1][m - 1] = mp[n - 1][m - 1];
  dl[n - 1][0] = mp[n - 1][0];
  ur[0][m - 1] = mp[0][m - 1];
  ul[0][0] = mp[0][0];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (i == 0 && j == 0) continue;
      if (i > 0) smax(ul[i][j], mp[i][j] + ul[i - 1][j]);
      if (j > 0) smax(ul[i][j], mp[i][j] + ul[i][j - 1]);
    }
    for (long long j = m - 1; ~j; j--) {
      if (i == 0 && j == m - 1) continue;
      if (i > 0) smax(ur[i][j], mp[i][j] + ur[i - 1][j]);
      if (j < m - 1) smax(ur[i][j], mp[i][j] + ur[i][j + 1]);
    }
  }
  for (long long i = n - 1; ~i; i--) {
    for (long long j = 0; j < m; j++) {
      if (i == n - 1 && j == 0) continue;
      if (i < n - 1) smax(dl[i][j], mp[i][j] + dl[i + 1][j]);
      if (j > 0) smax(dl[i][j], mp[i][j] + dl[i][j - 1]);
    }
    for (long long j = m - 1; ~j; j--) {
      if (i == n - 1 && j == m - 1) continue;
      if (i < n - 1) smax(dr[i][j], mp[i][j] + dr[i + 1][j]);
      if (j < m - 1) smax(dr[i][j], mp[i][j] + dr[i][j + 1]);
    }
  }
  for (long long i = 1; i < n - 1; i++)
    for (long long j = 1; j < m - 1; j++) {
      smax(ans, dl[i][j - 1] + ur[i][j + 1] + ul[i - 1][j] + dr[i + 1][j]);
      smax(ans, dl[i + 1][j] + ur[i - 1][j] + ul[i][j - 1] + dr[i][j + 1]);
    }
  cout << ans << endl;
  return 0;
}
