#include <bits/stdc++.h>
const long long INF = (long long)1e9;
const long double EPS = 0.000000000000001;
const long long MOD = (long long)1e9 + 7;
using namespace std;
long long n, m;
bool check_coor(long long x, long long y) {
  return (x >= 0) && (x < n) && (y >= 0) && (y < m);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  vector<vector<long long> > field(n, vector<long long>(m));
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      cin >> field[i][j];
    }
  }
  vector<vector<long long> > dp1_end(n, vector<long long>(m));
  vector<vector<long long> > dp2_end(n, vector<long long>(m));
  vector<vector<long long> > dp1_begin(n, vector<long long>(m));
  vector<vector<long long> > dp2_begin(n, vector<long long>(m));
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) {
      dp1_end[i][j] = max((i > 0 ? dp1_end[i - 1][j] : 0),
                          (j > 0 ? dp1_end[i][j - 1] : 0)) +
                      field[i][j];
    }
  }
  for (long long i = n - 1; i > -1; --i) {
    for (long long j = 0; j < m; ++j) {
      dp2_end[i][j] = max((i < n - 1 ? dp2_end[i + 1][j] : 0),
                          (j > 0 ? dp2_end[i][j - 1] : 0)) +
                      field[i][j];
    }
  }
  for (long long i = n - 1; i > -1; --i) {
    for (long long j = m - 1; j > -1; --j) {
      dp1_begin[i][j] = max((i < n - 1 ? dp1_begin[i + 1][j] : 0),
                            (j < m - 1 ? dp1_begin[i][j + 1] : 0)) +
                        field[i][j];
    }
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = m - 1; j > -1; --j) {
      dp2_begin[i][j] = max((i > 0 ? dp2_begin[i - 1][j] : 0),
                            (j < m - 1 ? dp2_begin[i][j + 1] : 0)) +
                        field[i][j];
    }
  }
  long long max_sum = 0;
  for (long long i = 1; i < n - 1; ++i) {
    for (long long j = 1; j < m - 1; ++j) {
      max_sum =
          max(max_sum, max(dp1_end[i - 1][j] + dp2_end[i][j - 1] +
                               dp1_begin[i + 1][j] + dp2_begin[i][j + 1],
                           dp1_end[i][j - 1] + dp2_end[i + 1][j] +
                               dp1_begin[i][j + 1] + dp2_begin[i - 1][j]));
    }
  }
  cout << max_sum << '\n';
  return 0;
}
