#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 5;
int a[MAXN][MAXN];
int g1[MAXN][MAXN], g2[MAXN][MAXN], g3[MAXN][MAXN], g4[MAXN][MAXN];
int n, m;
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  memset(g1, 0, sizeof(g1));
  g1[0][0] = a[0][0];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (i < n - 1) g1[i + 1][j] = max(g1[i + 1][j], g1[i][j] + a[i + 1][j]);
      if (j < m - 1) g1[i][j + 1] = max(g1[i][j + 1], g1[i][j] + a[i][j + 1]);
    }
  memset(g2, 0, sizeof(g2));
  g2[0][m - 1] = a[0][m - 1];
  for (int i = 0; i < n; i++)
    for (int j = m - 1; j >= 0; j--) {
      if (i < n - 1) g2[i + 1][j] = max(g2[i + 1][j], g2[i][j] + a[i + 1][j]);
      if (j > 0) g2[i][j - 1] = max(g2[i][j - 1], g2[i][j] + a[i][j - 1]);
    }
  memset(g3, 0, sizeof(g3));
  g3[n - 1][0] = a[n - 1][0];
  for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < m; j++) {
      if (i > 0) g3[i - 1][j] = max(g3[i - 1][j], g3[i][j] + a[i - 1][j]);
      if (j < m - 1) g3[i][j + 1] = max(g3[i][j + 1], g3[i][j] + a[i][j + 1]);
    }
  memset(g4, 0, sizeof(g4));
  g4[n - 1][m - 1] = a[n - 1][m - 1];
  for (int i = n - 1; i >= 0; i--)
    for (int j = m - 1; j >= 0; j--) {
      if (i > 0) g4[i - 1][j] = max(g4[i - 1][j], g4[i][j] + a[i - 1][j]);
      if (j > 0) g4[i][j - 1] = max(g4[i][j - 1], g4[i][j] + a[i][j - 1]);
    }
  int ans = 0;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      ans = max(ans, g1[i - 1][j] + g2[i][j + 1] + g3[i][j - 1] + g4[i + 1][j]);
      ans = max(ans, g1[i][j - 1] + g2[i - 1][j] + g3[i + 1][j] + g4[i][j + 1]);
    }
  printf("%d\n", ans);
}
