#include <bits/stdc++.h>
using namespace std;
int boy_start[1005][1005];
int girl_start[1005][1005];
int boy_end[1005][1005];
int girl_end[1005][1005];
int calorie[1005][1005];
int solve(int n, int m) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0)
        boy_start[i][j] = calorie[i][j];
      else if (i == 0)
        boy_start[i][j] = calorie[i][j] + boy_start[i][j - 1];
      else if (j == 0)
        boy_start[i][j] = calorie[i][j] + boy_start[i - 1][j];
      else
        boy_start[i][j] =
            calorie[i][j] + max(boy_start[i - 1][j], boy_start[i][j - 1]);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (i == n - 1 && j == 0)
        girl_start[i][j] = calorie[i][j];
      else if (i == n - 1)
        girl_start[i][j] = calorie[i][j] + girl_start[i][j - 1];
      else if (j == 0)
        girl_start[i][j] = calorie[i][j] + girl_start[i + 1][j];
      else
        girl_start[i][j] =
            calorie[i][j] + max(girl_start[i + 1][j], girl_start[i][j - 1]);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (i == n - 1 && j == m - 1)
        boy_end[i][j] = calorie[i][j];
      else if (i == n - 1)
        boy_end[i][j] = calorie[i][j] + boy_end[i][j + 1];
      else if (j == m - 1)
        boy_end[i][j] = calorie[i][j] + boy_end[i + 1][j];
      else
        boy_end[i][j] =
            calorie[i][j] + max(boy_end[i + 1][j], boy_end[i][j + 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (i == 0 && j == m - 1)
        girl_end[i][j] = calorie[i][j];
      else if (i == 0)
        girl_end[i][j] = calorie[i][j] + girl_end[i][j + 1];
      else if (j == m - 1)
        girl_end[i][j] = calorie[i][j] + girl_end[i - 1][j];
      else
        girl_end[i][j] =
            calorie[i][j] + max(girl_end[i - 1][j], girl_end[i][j + 1]);
    }
  }
  int ans = INT_MIN;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      int op1 = boy_start[i - 1][j] + boy_end[i + 1][j] + girl_start[i][j - 1] +
                girl_end[i][j + 1];
      int op2 = boy_start[i][j - 1] + boy_end[i][j + 1] + girl_start[i + 1][j] +
                girl_end[i - 1][j];
      ans = max(ans, max(op1, op2));
    }
  }
  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));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      calorie[i][j] = x;
    }
  }
  cout << solve(n, m) << endl;
}
