#include <bits/stdc++.h>
using namespace std;
const int NN = 1005;
int boy_start[NN][NN];
int boy_end[NN][NN];
int girl_start[NN][NN];
int girl_end[NN][NN];
int calories[NN][NN];
int maxCalories(int M, int N) {
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      boy_start[i][j] =
          calories[i][j] + max(boy_start[i - 1][j], boy_start[i][j - 1]);
    }
  }
  for (int i = M; i >= 1; i--) {
    for (int j = 1; j <= N; j++) {
      girl_start[i][j] =
          calories[i][j] + max(girl_start[i + 1][j], girl_start[i][j - 1]);
    }
  }
  for (int i = M; i >= 1; i--) {
    for (int j = N; j >= 1; j--) {
      boy_end[i][j] =
          calories[i][j] + max(boy_end[i + 1][j], boy_end[i][j + 1]);
    }
  }
  for (int i = 1; i <= M; i++) {
    for (int j = N; j >= 1; j--) {
      girl_end[i][j] =
          calories[i][j] + max(girl_end[i - 1][j], girl_end[i][j + 1]);
    }
  }
  int ans = 0;
  for (int i = 2; i < M; i++) {
    for (int j = 2; j < N; j++) {
      int ans1 = boy_start[i - 1][j] + girl_start[i][j - 1] +
                 boy_end[i + 1][j] + girl_end[i][j + 1];
      int ans2 = boy_start[i][j - 1] + girl_start[i + 1][j] +
                 boy_end[i][j + 1] + girl_end[i - 1][j];
      ans = max(ans, max(ans1, ans2));
    }
  }
  return ans;
}
int main() {
  memset(boy_start, 0, sizeof(boy_start));
  memset(boy_end, 0, sizeof(boy_end));
  memset(girl_start, 0, sizeof(girl_start));
  memset(girl_end, 0, sizeof(girl_end));
  memset(calories, 0, sizeof(calories));
  int M, N;
  cin >> M >> N;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> calories[i][j];
    }
  }
  cout << maxCalories(M, N) << endl;
  return 0;
}
