#include <bits/stdc++.h>
using namespace std;
int m, n;
int **a;
int **zika1, **zika2;
int **julka1, **julka2;
int max(int x, int y) { return x > y ? x : y; }
int main() {
  int i, j;
  cin >> m >> n;
  a = (int **)malloc((m + 1) * sizeof(int *));
  zika1 = (int **)malloc((m + 1) * sizeof(int *));
  zika2 = (int **)malloc((m + 1) * sizeof(int *));
  julka1 = (int **)malloc((m + 1) * sizeof(int *));
  julka2 = (int **)malloc((m + 1) * sizeof(int *));
  for (i = 1; i <= m; i++) {
    a[i] = (int *)malloc((n + 1) * sizeof(int));
    for (j = 1; j <= n; j++) cin >> a[i][j];
    zika1[i] = (int *)calloc((n + 1), sizeof(int));
    zika2[i] = (int *)calloc((n + 1), sizeof(int));
    julka1[i] = (int *)calloc((n + 1), sizeof(int));
    julka2[i] = (int *)calloc((n + 1), sizeof(int));
  }
  zika1[1][1] = a[1][1];
  julka1[m][1] = a[m][1];
  for (j = 2; j <= n; j++) {
    zika1[1][j] = a[1][j] + zika1[1][j - 1];
    julka1[m][j] = a[m][j] + julka1[m][j - 1];
  }
  zika2[m][n] = a[m][n];
  julka2[1][n] = a[1][n];
  for (j = n - 1; j > 0; j--) {
    zika2[m][j] = a[m][j] + zika2[m][j + 1];
    julka2[1][j] = a[1][j] + julka2[1][j + 1];
  }
  zika1[1][1] = a[1][1];
  julka2[1][n] = a[1][n];
  for (i = 2; i <= m; i++) {
    zika1[i][1] = a[i][1] + zika1[i - 1][1];
    julka2[i][n] = a[i][n] + julka2[i - 1][n];
  }
  zika2[m][n] = a[m][n];
  julka1[m][1] = a[m][1];
  for (i = m - 1; i > 0; i--) {
    zika2[i][n] = a[i][n] + zika2[i + 1][n];
    julka1[i][1] = a[i][1] + julka1[i + 1][1];
  }
  for (i = 2; i <= m; i++)
    for (j = 2; j <= n; j++)
      zika1[i][j] = a[i][j] + max(zika1[i - 1][j], zika1[i][j - 1]);
  for (i = m - 1; i > 0; i--)
    for (j = n - 1; j > 0; j--)
      zika2[i][j] = a[i][j] + max(zika2[i + 1][j], zika2[i][j + 1]);
  for (i = m - 1; i > 0; i--)
    for (j = 2; j <= n; j++)
      julka1[i][j] = a[i][j] + max(julka1[i + 1][j], julka1[i][j - 1]);
  for (i = 2; i <= m; i++)
    for (j = n - 1; j > 0; j--)
      julka2[i][j] = a[i][j] + max(julka2[i - 1][j], julka2[i][j + 1]);
  int max = -1;
  for (i = 2; i < m; i++)
    for (j = 2; j < n; j++) {
      int sum1 = zika1[i - 1][j] + zika2[i + 1][j] + julka1[i][j - 1] +
                 julka2[i][j + 1];
      int sum2 = zika1[i][j - 1] + zika2[i][j + 1] + julka1[i + 1][j] +
                 julka2[i - 1][j];
      if (sum1 > max) max = sum1;
      if (sum2 > max) max = sum2;
    }
  cout << max << endl;
  return 0;
}
