#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 1005;
int n, m;
long long int a[N][N];
long long int b[4][N][N];
void maxi() {
  for (int i = 1; i < n + 1; i += 1) {
    for (int j = 1; j < m + 1; j += 1) {
      b[0][i][j] = max(b[0][i - 1][j], b[0][i][j - 1]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i -= 1) {
    for (int j = 1; j < m + 1; j += 1) {
      b[1][i][j] = max(b[1][i + 1][j], b[1][i][j - 1]) + a[i][j];
    }
  }
  for (int i = 1; i < n + 1; i += 1) {
    for (int j = m; j >= 1; j -= 1) {
      b[2][i][j] = max(b[2][i - 1][j], b[2][i][j + 1]) + a[i][j];
    }
  }
  for (int i = n; i >= 1; i -= 1) {
    for (int j = m; j >= 1; j -= 1) {
      b[3][i][j] = max(b[3][i + 1][j], b[3][i][j + 1]) + a[i][j];
    }
  }
}
long long int workOut() {
  long long int maxN = 0;
  for (int i = 2; i < n; i += 1) {
    for (int j = 2; j < m; j += 1) {
      maxN = max(
          max(maxN, b[0][i - 1][j] + b[1][i][j - 1] + b[2][i][j + 1] +
                        b[3][i + 1][j]),
          b[0][i][j - 1] + b[1][i + 1][j] + b[2][i - 1][j] + b[3][i][j + 1]);
    }
  }
  return maxN;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n + 1; i += 1) {
    for (int j = 1; j < m + 1; j += 1) {
      cin >> a[i][j];
    }
  }
  maxi();
  cout << workOut();
  return 0;
}
