#include <bits/stdc++.h>
using namespace std;
long long dp[5][1005][1005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int a;
      scanf("%d", &a);
      for (int k = 1; k <= 4; k++) dp[k][i][j] = a;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      dp[1][i][j] += max(dp[1][i - 1][j], dp[1][i][j - 1]);
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      dp[2][i][j] += max(dp[2][i - 1][j], dp[2][i][j + 1]);
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      dp[3][i][j] += max(dp[3][i + 1][j], dp[3][i][j + 1]);
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      dp[4][i][j] += max(dp[4][i][j - 1], dp[4][i + 1][j]);
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i == 1 || i == n) continue;
      if (j == 1 || j == m) continue;
      ans = max(ans, dp[1][i - 1][j] + dp[2][i][j + 1] + dp[3][i + 1][j] +
                         dp[4][i][j - 1]);
      ans = max(ans, dp[1][i][j - 1] + dp[2][i - 1][j] + dp[3][i][j + 1] +
                         dp[4][i + 1][j]);
    }
  cout << ans << endl;
  return 0;
}
