#include <bits/stdc++.h>
using namespace std;
long long arr[1002][1002];
long long v1[1002][1002];
long long v2[1002][1002];
long long v3[1002][1002];
long long v4[1002][1002];
long long n, m;
void dpfill1() {
  v1[0][0] = arr[0][0];
  for (__typeof(n - 1) i = 1; i <= n - 1; i++) {
    v1[i][0] = arr[i][0] + v1[i - 1][0];
  }
  for (__typeof(m - 1) j = 1; j <= m - 1; j++)
    v1[0][j] = arr[0][j] + v1[0][j - 1];
  for (__typeof(n - 1) i = 1; i <= n - 1; i++)
    for (__typeof(m - 1) j = 1; j <= m - 1; j++) {
      v1[i][j] = arr[i][j] + max(v1[i - 1][j], v1[i][j - 1]);
    }
}
void dpfill2() {
  v2[n - 1][0] = arr[n - 1][0];
  for (__typeof(n - 2) i = n - 2; i >= 0; i--)
    v2[i][0] = arr[i][0] + v2[i + 1][0];
  for (__typeof(m - 1) j = 1; j <= m - 1; j++)
    v2[n - 1][j] = arr[n - 1][j] + v2[n - 1][j - 1];
  for (__typeof(n - 2) i = n - 2; i >= 0; i--)
    for (__typeof(m - 1) j = 1; j <= m - 1; j++) {
      v2[i][j] = arr[i][j] + max(v2[i + 1][j], v2[i][j - 1]);
    }
}
void dpfill3() {
  v3[0][m - 1] = arr[0][m - 1];
  for (__typeof(n - 1) i = 1; i <= n - 1; i++)
    v3[i][m - 1] = arr[i][m - 1] + v3[i - 1][m - 1];
  for (__typeof(m - 2) j = m - 2; j >= 0; j--)
    v3[0][j] = arr[0][j] + v3[0][j + 1];
  for (__typeof(n - 1) i = 1; i <= n - 1; i++)
    for (__typeof(m - 2) j = m - 2; j >= 0; j--) {
      v3[i][j] = arr[i][j] + max(v3[i - 1][j], v3[i][j + 1]);
    }
}
void dpfill4() {
  v4[n - 1][m - 1] = arr[n - 1][m - 1];
  for (__typeof(n - 2) i = n - 2; i >= 0; i--)
    v4[i][m - 1] = arr[i][m - 1] + v4[i + 1][m - 1];
  for (__typeof(m - 2) j = m - 2; j >= 0; j--)
    v4[n - 1][j] = arr[n - 1][j] + v4[n - 1][j + 1];
  for (__typeof(n - 2) i = n - 2; i >= 0; i--)
    for (__typeof(m - 2) j = m - 2; j >= 0; j--) {
      v4[i][j] = arr[i][j] + max(v4[i + 1][j], v4[i][j + 1]);
    }
}
int main() {
  memset(arr, 0, sizeof(arr));
  memset(v1, 0, sizeof(arr));
  memset(v2, 0, sizeof(arr));
  memset(v3, 0, sizeof(arr));
  memset(v4, 0, sizeof(arr));
  scanf("%lld%lld", &n, &m);
  for (__typeof(n) i = 0; i < n; i++) {
    for (__typeof(m) j = 0; j < m; j++) cin >> arr[i][j];
  }
  dpfill1();
  dpfill2();
  dpfill3();
  dpfill4();
  long long maxx = 0;
  for (__typeof(n - 2) i = 1; i <= n - 2; i++)
    for (__typeof(m - 2) j = 1; j <= m - 2; j++) {
      long long one = v1[i - 1][j] + v2[i][j - 1] + v4[i + 1][j] + v3[i][j + 1];
      long long two = v1[i][j - 1] + v2[i + 1][j] + v4[i][j + 1] + v3[i - 1][j];
      maxx = max(maxx, max(one, two));
    }
  printf("%lld\n", maxx);
}
