#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
template <class A, class B>
ostream& operator<<(ostream& os, pair<A, B> p) {
  return os << p.first << " " << p.second;
}
template <class A, class B>
istream& operator>>(istream& is, pair<A, B>& p) {
  return is >> p.first >> p.second;
}
const int oo = 0x3f3f3f3f;
const ll OO = ll(oo) * oo;
const int N = 1005;
int dp[4][N][N];
int a[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i + 1][j + 1];
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < m + 1; j++) {
      dp[0][i][j] = a[i][j] + max(dp[0][i - 1][j], dp[0][i][j - 1]);
    }
  for (int i = 1; i < n + 1; i++)
    for (int j = m; j > 0; j--) {
      dp[1][i][j] = a[i][j] + max(dp[1][i - 1][j], dp[1][i][j + 1]);
    }
  for (int i = n; i > 0; i--)
    for (int j = 1; j < m + 1; j++) {
      dp[2][i][j] = a[i][j] + max(dp[2][i + 1][j], dp[2][i][j - 1]);
    }
  for (int i = n; i > 0; i--)
    for (int j = m; j > 0; j--) {
      dp[3][i][j] = a[i][j] + max(dp[3][i + 1][j], dp[3][i][j + 1]);
    }
  int best = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      best = max(best, dp[0][i - 1][j] + dp[3][i + 1][j] + dp[2][i][j - 1] +
                           dp[1][i][j + 1]);
      best = max(best, dp[0][i][j - 1] + dp[3][i][j + 1] + dp[2][i + 1][j] +
                           dp[1][i - 1][j]);
    }
  cout << best << '\n';
  return 0;
}
