#include <bits/stdc++.h>
using namespace std;
struct p {
  int x;
  int dp[4];
} a[1010][1010];
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j].x;
      for (int l = 0; l < 4; l++) a[i][j].dp[l] = a[i][j].x;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      a[i][j].dp[0] += max(a[i - 1][j].dp[0], a[i][j - 1].dp[0]);
  for (int i = n; i >= 0; i--)
    for (int j = m; j >= 0; j--)
      a[i][j].dp[1] += max(a[i + 1][j].dp[1], a[i][j + 1].dp[1]);
  for (int i = n; i >= 0; i--)
    for (int j = 1; j <= m; j++)
      a[i][j].dp[2] += max(a[i + 1][j].dp[2], a[i][j - 1].dp[2]);
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 0; j--)
      a[i][j].dp[3] += max(a[i - 1][j].dp[3], a[i][j + 1].dp[3]);
  long long ans = 0;
  for (int i = 2; i <= n - 1; i++)
    for (int j = 2; j <= m - 1; j++) {
      ans = max(ans, (long long)a[i - 1][j].dp[0] + a[i + 1][j].dp[1] +
                         a[i][j - 1].dp[2] + a[i][j + 1].dp[3]);
      ans = max(ans, (long long)a[i][j - 1].dp[0] + a[i][j + 1].dp[1] +
                         a[i + 1][j].dp[2] + a[i - 1][j].dp[3]);
    }
  cout << ans << endl;
  return 0;
}
