#include <bits/stdc++.h>
using pii = std::pair<long long, long long>;
using namespace std;
long long n, m, a[1005][1005], dp[1005][1005][4] = {0};
class BWorkingOut {
 public:
  void solve(std::istream& in, std::ostream& out) {
    in >> n >> m;
    for (long long i = (0); i < (n); i++)
      for (long long j = (0); j < (m); j++) in >> a[i][j];
    dp[0][0][0] = a[0][0];
    dp[n - 1][0][1] = a[n - 1][0];
    dp[n - 1][m - 1][2] = a[n - 1][m - 1];
    dp[0][m - 1][3] = a[0][m - 1];
    for (long long i = (0); i < (n); i++)
      for (long long j = (0); j < (m); j++) {
        if (i < n - 1)
          dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][0] + a[i + 1][j]);
        if (j < m - 1)
          dp[i][j + 1][0] = max(dp[i][j + 1][0], dp[i][j][0] + a[i][j + 1]);
      }
    for (long long i = n - 1; i >= 0; i--)
      for (long long j = (0); j < (m); j++) {
        if (i > 0)
          dp[i - 1][j][1] = max(dp[i - 1][j][1], dp[i][j][1] + a[i - 1][j]);
        if (j < m - 1)
          dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][1] + a[i][j + 1]);
      }
    for (long long i = n - 1; i >= 0; i--)
      for (long long j = m - 1; j >= 0; j--) {
        if (i > 0)
          dp[i - 1][j][2] = max(dp[i - 1][j][2], dp[i][j][2] + a[i - 1][j]);
        if (j > 0)
          dp[i][j - 1][2] = max(dp[i][j - 1][2], dp[i][j][2] + a[i][j - 1]);
      }
    for (long long i = (0); i < (n); i++)
      for (long long j = m - 1; j >= 0; j--) {
        if (i < n - 1)
          dp[i + 1][j][3] = max(dp[i + 1][j][3], dp[i][j][3] + a[i + 1][j]);
        if (j > 0)
          dp[i][j - 1][3] = max(dp[i][j - 1][3], dp[i][j][3] + a[i][j - 1]);
      }
    long long ans = 0;
    for (long long i = (1); i < (n - 1); i++)
      for (long long j = (1); j < (m - 1); j++)
        ans = max(ans, max(dp[i - 1][j][0] + dp[i][j - 1][1] + dp[i + 1][j][2] +
                               dp[i][j + 1][3],
                           dp[i][j - 1][0] + dp[i + 1][j][1] + dp[i][j + 1][2] +
                               dp[i - 1][j][3]));
    out << ans << "\n";
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  BWorkingOut solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
