#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000;
int m, n;
int g[MaxN][MaxN];
int A1[MaxN][MaxN], A2[MaxN][MaxN];
int B1[MaxN][MaxN], B2[MaxN][MaxN];
bool Input() {
  if (cin >> n >> m) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> g[i][j];
    return true;
  }
  return false;
}
void PreProcess() {
  int top, left, right, bottom;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      top = ((i - 1) >= 0) ? A1[i - 1][j] : 0;
      left = ((j - 1) >= 0) ? A1[i][j - 1] : 0;
      A1[i][j] = g[i][j] + max(top, left);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      bottom = ((i + 1) < n) ? A2[i + 1][j] : 0;
      right = ((j + 1) < m) ? A2[i][j + 1] : 0;
      A2[i][j] = g[i][j] + max(bottom, right);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      bottom = ((i + 1) < n) ? B1[i + 1][j] : 0;
      left = ((j - 1) >= 0) ? B1[i][j - 1] : 0;
      B1[i][j] = g[i][j] + max(bottom, left);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      top = ((i - 1) >= 0) ? B2[i - 1][j] : 0;
      right = ((j + 1) < m) ? B2[i][j + 1] : 0;
      B2[i][j] = g[i][j] + max(top, right);
    }
  }
}
int Solve() {
  int maxGain, gain1, gain2;
  maxGain = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      gain1 = A1[i - 1][j] + A2[i + 1][j] + B1[i][j - 1] + B2[i][j + 1];
      gain2 = A1[i][j - 1] + A2[i][j + 1] + B1[i + 1][j] + B2[i - 1][j];
      maxGain = max(maxGain, max(gain1, gain2));
    }
  }
  return maxGain;
}
int main() {
  while (Input()) {
    PreProcess();
    cout << Solve() << endl;
  }
  return 0;
}
