#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long arr[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  long long a[n][m], b[n][m], c[n][m], d[n][m];
  a[0][0] = arr[0][0], b[n - 1][m - 1] = arr[n - 1][m - 1],
  c[n - 1][0] = arr[n - 1][0], d[0][m - 1] = arr[0][m - 1];
  for (int i = 1; i < n; ++i) {
    a[i][0] = a[i - 1][0] + arr[i][0];
    b[n - i - 1][m - 1] = b[n - i][m - 1] + arr[n - i - 1][m - 1];
    c[n - i - 1][0] = c[n - i][0] + arr[n - i - 1][0];
    d[i][m - 1] = d[i - 1][m - 1] + arr[i][m - 1];
  }
  for (int i = 1; i < m; ++i) {
    a[0][i] = a[0][i - 1] + arr[0][i];
    b[n - 1][m - i - 1] = b[n - 1][m - i] + arr[n - 1][m - i - 1];
    c[n - 1][i] = c[n - 1][i - 1] + arr[n - 1][i];
    d[0][m - i - 1] = d[0][m - i] + arr[0][m - i - 1];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      a[i][j] = arr[i][j] + max(a[i - 1][j], a[i][j - 1]);
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    for (int j = m - 2; j >= 0; --j) {
      b[i][j] = arr[i][j] + max(b[i + 1][j], b[i][j + 1]);
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    for (int j = 1; j < m; ++j) {
      c[i][j] = arr[i][j] + max(c[i + 1][j], c[i][j - 1]);
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = m - 2; j >= 0; --j) {
      d[i][j] = arr[i][j] + max(d[i - 1][j], d[i][j + 1]);
    }
  }
  long long ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    for (int j = 1; j < m - 1; ++j) {
      ans = max(ans, a[i - 1][j] + b[i + 1][j] + c[i][j - 1] + d[i][j + 1]);
      ans = max(ans, a[i][j - 1] + b[i][j + 1] + c[i + 1][j] + d[i - 1][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
