#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[n + 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  long long bs[n + 2][m + 2];
  long long be[n + 2][m + 2];
  long long gs[n + 2][m + 2];
  long long ge[n + 2][m + 2];
  memset(bs, 0, sizeof(bs));
  memset(be, 0, sizeof(be));
  memset(gs, 0, sizeof(gs));
  memset(ge, 0, sizeof(ge));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      bs[i][j] = a[i][j] + max(bs[i - 1][j], bs[i][j - 1]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      gs[i][j] = a[i][j] + max(gs[i][j - 1], gs[i + 1][j]);
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      be[i][j] = a[i][j] + max(be[i][j + 1], be[i + 1][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      ge[i][j] = a[i][j] + max(ge[i][j + 1], ge[i - 1][j]);
    }
  }
  long long ans = 0;
  for (int i = 2; i <= n - 1; i++) {
    for (int j = 2; j <= m - 1; j++) {
      long long c1 = bs[i - 1][j] + be[i + 1][j] + gs[i][j - 1] + ge[i][j + 1];
      long long c2 = bs[i][j - 1] + be[i][j + 1] + gs[i + 1][j] + ge[i - 1][j];
      ans = max(ans, max(c1, c2));
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int testcases;
  testcases = 1;
  while (testcases--) {
    solve();
  }
  return 0;
}
