#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e18;
long long int mod = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
const int K = 1005;
int dp1[K][K];
int dp3[K][K];
int dp2[K][K];
int dp4[K][K];
int cal[K][K];
int maxCal(int M, int N) {
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      dp1[i][j] = cal[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
    }
  }
  for (int i = M; i >= 1; i--) {
    for (int j = 1; j <= N; j++) {
      dp2[i][j] = cal[i][j] + max(dp2[i + 1][j], dp2[i][j - 1]);
    }
  }
  for (int i = M; i >= 0; i--) {
    for (int j = N; j >= 1; j--) {
      dp3[i][j] = cal[i][j] + max(dp3[i + 1][j], dp3[i][j + 1]);
    }
  }
  for (int i = 1; i <= M; i++) {
    for (int j = N; j >= 1; j--) {
      dp4[i][j] = cal[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]);
    }
  }
  int ans = 0;
  for (int i = 2; i <= M - 1; i++) {
    for (int j = 2; j <= N - 1; j++) {
      int ans1 = dp1[i][j - 1] + dp3[i][j + 1] + dp2[i + 1][j] + dp4[i - 1][j];
      int ans2 = dp1[i - 1][j] + dp3[i + 1][j] + dp2[i][j - 1] + dp4[i][j + 1];
      ans = max(ans, max(ans1, ans2));
    }
  }
  return ans;
}
int main() {
  memset(dp1, 0, sizeof dp1);
  memset(dp3, 0, sizeof dp3);
  memset(dp2, 0, sizeof dp2);
  memset(dp4, 0, sizeof dp4);
  memset(cal, 0, sizeof cal);
  int M, N;
  cin >> M >> N;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> cal[i][j];
    }
  }
  cout << maxCal(M, N) << endl;
  return 0;
}
