#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
int d[5][1010][1010];
int n, m;
void find1() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (i == 0 && j == 0)
        d[0][i][j] = a[i][j];
      else if (i == 0)
        d[0][i][j] = d[0][i][j - 1] + a[i][j];
      else if (j == 0)
        d[0][i][j] = d[0][i - 1][j] + a[i][j];
      else
        d[0][i][j] = max(d[0][i - 1][j], d[0][i][j - 1]) + a[i][j];
    }
}
void find2() {
  for (int i = n - 1; i >= 0; --i)
    for (int j = 0; j < m; ++j) {
      if (i == n - 1 && j == 0)
        d[1][i][j] = a[i][j];
      else if (i == n - 1)
        d[1][i][j] = d[1][i][j - 1] + a[i][j];
      else if (j == 0)
        d[1][i][j] = d[1][i + 1][j] + a[i][j];
      else
        d[1][i][j] = max(d[1][i + 1][j], d[1][i][j - 1]) + a[i][j];
    }
}
void find3() {
  for (int i = 0; i < n; ++i)
    for (int j = m - 1; j >= 0; --j) {
      if (i == 0 && j == m - 1)
        d[2][i][j] = a[i][j];
      else if (i == 0)
        d[2][i][j] = d[2][i][j + 1] + a[i][j];
      else if (j == m - 1)
        d[2][i][j] = d[2][i - 1][j] + a[i][j];
      else
        d[2][i][j] = max(d[2][i - 1][j], d[2][i][j + 1]) + a[i][j];
    }
}
void find4() {
  for (int i = n - 1; i >= 0; --i)
    for (int j = m - 1; j >= 0; --j) {
      if (i == n - 1 && j == m - 1)
        d[3][i][j] = a[i][j];
      else if (i == n - 1)
        d[3][i][j] = d[3][i][j + 1] + a[i][j];
      else if (j == m - 1)
        d[3][i][j] = d[3][i + 1][j] + a[i][j];
      else
        d[3][i][j] = max(d[3][i + 1][j], d[3][i][j + 1]) + a[i][j];
    }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  find1();
  find2();
  find3();
  find4();
  int ans = 0;
  for (int i = 1; i < n - 1; ++i)
    for (int j = 1; j < m - 1; ++j) {
      ans = max(ans, d[0][i][j - 1] + d[1][i + 1][j] + d[2][i - 1][j] +
                         d[3][i][j + 1]);
      ans = max(ans, d[0][i - 1][j] + d[1][i][j - 1] + d[2][i][j + 1] +
                         d[3][i + 1][j]);
    }
  cout << ans << "\n";
  return 0;
}
