#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
int n, m;
int a[1000][1000];
int dps[4][1000][1000];
void calc(int dp[][1000], int sy, int sx, int dy, int dx) {
  for (int y = sy; 0 <= y && y < n; y += dy)
    for (int x = sx; 0 <= x && x < m; x += dx) {
      int t = 0;
      if (0 <= y - dy && y - dy < n) amax(t, dp[y - dy][x]);
      if (0 <= x - dx && x - dx < m) amax(t, dp[y][x - dx]);
      dp[y][x] = t + a[y][x];
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = 0; (i) < (int)(n); ++(i))
    for (int(j) = 0; (j) < (int)(m); ++(j)) scanf("%d", &a[i][j]);
  calc(dps[0], 0, 0, 1, 1);
  calc(dps[1], n - 1, m - 1, -1, -1);
  calc(dps[2], n - 1, 0, -1, 1);
  calc(dps[3], 0, m - 1, 1, -1);
  int ans = -1;
  for (int(y) = (int)(1); (y) < (int)(n - 1); ++(y))
    for (int(x) = (int)(1); (x) < (int)(m - 1); ++(x)) {
      {
        int t = 0;
        t += dps[0][y - 1][x];
        t += dps[1][y + 1][x];
        t += dps[2][y][x - 1];
        t += dps[3][y][x + 1];
        amax(ans, t);
      }
      {
        int t = 0;
        t += dps[0][y][x - 1];
        t += dps[1][y][x + 1];
        t += dps[2][y + 1][x];
        t += dps[3][y - 1][x];
        amax(ans, t);
      }
    }
  printf("%d\n", ans);
  return 0;
}
