#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
int dl[1000][1000];
int dr[1000][1000];
int ul[1000][1000];
int ur[1000][1000];
int g[1000][1000];
int n, m;
int recdl(int i, int j) {
  if (i < 0 || i == n || j < 0 || j == m) return -1001001001;
  if (i == n - 1 && j == 0) return g[i][j];
  if (dl[i][j] != -1) return dl[i][j];
  return dl[i][j] =
             g[i][j] + (recdl(i + 1, j) < recdl(i, j - 1) ? recdl(i, j - 1)
                                                          : recdl(i + 1, j));
}
int recdr(int i, int j) {
  if (i < 0 || i == n || j < 0 || j == m) return -1001001001;
  if (i == n - 1 && j == m - 1) return g[i][j];
  if (dr[i][j] != -1) return dr[i][j];
  return dr[i][j] =
             g[i][j] + (recdr(i + 1, j) < recdr(i, j + 1) ? recdr(i, j + 1)
                                                          : recdr(i + 1, j));
}
int recul(int i, int j) {
  if (i < 0 || i == n || j < 0 || j == m) return -1001001001;
  if (i == 0 && j == 0) return g[i][j];
  if (ul[i][j] != -1) return ul[i][j];
  return ul[i][j] =
             g[i][j] + (recul(i - 1, j) < recul(i, j - 1) ? recul(i, j - 1)
                                                          : recul(i - 1, j));
}
int recur(int i, int j) {
  if (i < 0 || i == n || j < 0 || j == m) return -1001001001;
  if (i == 0 && j == m - 1) return g[i][j];
  if (ur[i][j] != -1) return ur[i][j];
  return ur[i][j] =
             g[i][j] + (recur(i - 1, j) < recur(i, j + 1) ? recur(i, j + 1)
                                                          : recur(i - 1, j));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> g[i][j];
  memset(dl, -1, sizeof(dl));
  memset(dr, -1, sizeof(dr));
  memset(ul, -1, sizeof(ul));
  memset(ur, -1, sizeof(ur));
  int res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int b1 = recul(i - 1, j) + recdl(i, j - 1);
      int a1 = recdr(i + 1, j) + recur(i, j + 1);
      int b2 = recul(i, j - 1) + recdl(i + 1, j);
      int a2 = recdr(i, j + 1) + recur(i - 1, j);
      res = (res < (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1)
                 ? (b1 + a1 < b2 + a2 ? b2 + a2 : b1 + a1)
                 : res);
    }
  cout << res << endl;
}
