#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<long long>> v(n, vector<long long>(m));
  for (auto &i : v)
    for (auto &j : i) cin >> j;
  vector<vector<long long>> dp_from_top_left(n, vector<long long>(m, 0)),
      dp_from_top_right(n, vector<long long>(m, 0)),
      dp_from_bottom_left(n, vector<long long>(m, 0)),
      dp_from_bottom_right(n, vector<long long>(m, 0));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++)
      dp_from_top_left[i][j] = max((i > 0 ? dp_from_top_left[i - 1][j] : 0),
                                   (j > 0 ? dp_from_top_left[i][j - 1] : 0)) +
                               v[i][j];
  for (long long i = n - 1; i >= 0; i--)
    for (long long j = m - 1; j >= 0; j--)
      dp_from_bottom_right[i][j] =
          max((i < n - 1 ? dp_from_bottom_right[i + 1][j] : 0),
              (j < m - 1 ? dp_from_bottom_right[i][j + 1] : 0)) +
          v[i][j];
  for (long long i = n - 1; i >= 0; i--)
    for (long long j = 0; j < m; j++)
      dp_from_bottom_left[i][j] =
          max((i < n - 1 ? dp_from_bottom_left[i + 1][j] : 0),
              (j > 0 ? dp_from_bottom_left[i][j - 1] : 0)) +
          v[i][j];
  for (long long i = 0; i < n; i++)
    for (long long j = m - 1; j >= 0; j--)
      dp_from_top_right[i][j] =
          max((i > 0 ? dp_from_top_right[i - 1][j] : 0),
              (j < m - 1 ? dp_from_top_right[i][j + 1] : 0)) +
          v[i][j];
  long long ans = LLONG_MIN;
  for (long long i = 1; i < n - 1; i++) {
    for (long long j = 1; j < m - 1; j++) {
      ans = max(dp_from_top_left[i - 1][j] + dp_from_bottom_right[i + 1][j] +
                    dp_from_top_right[i][j + 1] + dp_from_bottom_left[i][j - 1],
                ans);
      ans = max(dp_from_top_left[i][j - 1] + dp_from_bottom_right[i][j + 1] +
                    dp_from_top_right[i - 1][j] + dp_from_bottom_left[i + 1][j],
                ans);
    }
  }
  cout << ans << "\n";
  return 0;
}
