#include <bits/stdc++.h>
int Boy1[1005][1005];
int Boy2[1005][1005];
int Girl1[1005][1005];
int Girl2[1005][1005];
using namespace std;
int main() {
  int N, M, ans, op1, op2;
  scanf("%d%d", &N, &M);
  int Workout[1005][1005];
  ans = 0;
  for (int i = (int)(1); i <= (int)(N); i++)
    for (int j = (int)(1); j <= (int)(M); j++) scanf("%d", &Workout[i][j]);
  for (int i = (int)(1); i <= (int)(N); i++)
    for (int j = (int)(1); j <= (int)(M); j++)
      Boy1[i][j] = max(Boy1[i - 1][j], Boy1[i][j - 1]) + Workout[i][j];
  for (int i = (int)(N); i >= (int)(1); i--)
    for (int j = (int)(M); j >= (int)(1); j--)
      Boy2[i][j] = max(Boy2[i + 1][j], Boy2[i][j + 1]) + Workout[i][j];
  for (int i = (int)(N); i >= (int)(1); i--)
    for (int j = (int)(1); j <= (int)(M); j++)
      Girl1[i][j] = max(Girl1[i + 1][j], Girl1[i][j - 1]) + Workout[i][j];
  for (int i = (int)(1); i <= (int)(N); i++)
    for (int j = (int)(M); j >= (int)(1); j--)
      Girl2[i][j] = max(Girl2[i - 1][j], Girl2[i][j + 1]) + Workout[i][j];
  for (int i = (int)(2); i <= (int)(N - 1); i++) {
    for (int j = (int)(2); j <= (int)(M - 1); 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;
}
