#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e3 + 7;
int Boy1[N][N], Boy2[N][N], Girl1[N][N], Girl2[N][N], Workout[N][N];
int main() {
  int n, m, ans, op1, op2;
  scanf("%d%d", &n, &m);
  ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &Workout[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      Boy1[i][j] = max(Boy1[i - 1][j], Boy1[i][j - 1]) + Workout[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      Boy2[i][j] = max(Boy2[i + 1][j], Boy2[i][j + 1]) + Workout[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= m; j++)
      Girl1[i][j] = max(Girl1[i + 1][j], Girl1[i][j - 1]) + Workout[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j >= 1; j--)
      Girl2[i][j] = max(Girl2[i - 1][j], Girl2[i][j + 1]) + Workout[i][j];
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++) {
      op1 = Boy1[i][j - 1] + Boy2[i][j + 1] + Girl1[i + 1][j] + Girl2[i - 1][j];
      op2 = Boy1[i - 1][j] + Boy2[i + 1][j] + Girl1[i][j - 1] + Girl2[i][j + 1];
      ans = max(ans, max(op1, op2));
    }
  printf("%d", ans);
  return 0;
}
