#include <bits/stdc++.h>
using namespace std;
int ag[1000][1000];
int ab[1000][1000];
int bg[1000][1000];
int bb[1000][1000];
int a[1000][1000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n;
  cin >> m;
  int min2 = 1000000000;
  int temp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  ag[0][0] = a[0][0];
  ab[n - 1][m - 1] = a[n - 1][m - 1];
  bg[n - 1][0] = a[n - 1][0];
  bb[0][m - 1] = a[0][m - 1];
  for (int i = 1; i < m; i++) {
    ag[0][i] = a[0][i] + ag[0][i - 1];
    bg[n - 1][i] = a[n - 1][i] + bg[n - 1][i - 1];
  }
  for (int i = m - 2; i >= 0; i--) {
    ab[n - 1][i] = a[n - 1][i] + ab[n - 1][i + 1];
    bb[0][i] = a[0][i] + bb[0][i + 1];
  }
  for (int i = 1; i < n; i++) {
    ag[i][0] = a[i][0] + ag[i - 1][0];
    bb[i][m - 1] = a[i][m - 1] + bb[i - 1][m - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    ab[i][m - 1] = a[i][m - 1] + ab[i + 1][m - 1];
    bg[i][0] = a[i][0] + bg[i + 1][0];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      ag[i][j] = a[i][j] + max(ag[i][j - 1], ag[i - 1][j]);
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 1; j < m; j++) {
      bg[i][j] = a[i][j] + max(bg[i][j - 1], bg[i + 1][j]);
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = m - 2; j >= 0; j--) {
      bb[i][j] = a[i][j] + max(bb[i][j + 1], bb[i - 1][j]);
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      ab[i][j] = a[i][j] + max(ab[i][j + 1], ab[i + 1][j]);
    }
  }
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      ans = max(ans, ag[i - 1][j] + ab[i + 1][j] + bg[i][j - 1] + bb[i][j + 1]);
      ans = max(ans, ag[i][j - 1] + ab[i][j + 1] + bg[i + 1][j] + bb[i - 1][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}
