#include <bits/stdc++.h>
using namespace std;
struct DirVal {
  long long topLeft;
  long long botLeft;
  long long topRight;
  long long botRight;
};
int A[1000][1000];
DirVal dp[1000][1000];
long long dpLeft[1000][1000];
long long dpRight[1000][1000];
int main() {
  ios::sync_with_stdio(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) cin >> A[i][j];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[i][j].topLeft = 0;
      if (i > 0) dp[i][j].topLeft = max(dp[i][j].topLeft, dp[i - 1][j].topLeft);
      if (j > 0) dp[i][j].topLeft = max(dp[i][j].topLeft, dp[i][j - 1].topLeft);
      dp[i][j].topLeft += A[i][j];
    }
  }
  for (int i = (N - 1); i >= 0; i--) {
    for (int j = 0; j < M; j++) {
      dp[i][j].botLeft = 0;
      if (i < (N - 1))
        dp[i][j].botLeft = max(dp[i][j].botLeft, dp[i + 1][j].botLeft);
      if (j > 0) dp[i][j].botLeft = max(dp[i][j].botLeft, dp[i][j - 1].botLeft);
      dp[i][j].botLeft += A[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = (M - 1); j >= 0; j--) {
      dp[i][j].topRight = 0;
      if (i > 0)
        dp[i][j].topRight = max(dp[i][j].topRight, dp[i - 1][j].topRight);
      if (j < (M - 1))
        dp[i][j].topRight = max(dp[i][j].topRight, dp[i][j + 1].topRight);
      dp[i][j].topRight += A[i][j];
    }
  }
  for (int i = (N - 1); i >= 0; i--) {
    for (int j = (M - 1); j >= 0; j--) {
      dp[i][j].botRight = 0;
      if (i < (N - 1))
        dp[i][j].botRight = max(dp[i][j].botRight, dp[i + 1][j].botRight);
      if (j < (M - 1))
        dp[i][j].botRight = max(dp[i][j].botRight, dp[i][j + 1].botRight);
      dp[i][j].botRight += A[i][j];
    }
  }
  long long ans = 0;
  long long cur;
  for (int i = 1; i < (N - 1); i++) {
    for (int j = 1; j < (M - 1); j++) {
      cur = max(dp[i - 1][j].topLeft + dp[i + 1][j].botRight +
                    dp[i][j - 1].botLeft + dp[i][j + 1].topRight,
                dp[i][j - 1].topLeft + dp[i][j + 1].botRight +
                    dp[i + 1][j].botLeft + dp[i - 1][j].topRight);
      ans = max(ans, cur);
    }
  }
  cout << ans << "\n";
}
