#include <bits/stdc++.h>
using namespace std;
int m, n;
int a[1010][1010];
void solve(int d[][1010], int dx, int dy) {
  for (int i = dx > 0 ? 1 : m; i >= 1 && i <= m; i += dx)
    for (int j = dy > 0 ? 1 : n; j >= 1 && j <= n; j += dy) {
      int x1 = i - dx, y1 = j;
      int x2 = i, y2 = j - dy;
      d[i][j] = max(d[x1][y1], d[x2][y2]) + a[i][j];
    }
}
int lu[1010][1010] = {0};
int ld[1010][1010] = {0};
int ru[1010][1010] = {0};
int rd[1010][1010] = {0};
int main() {
  scanf("%d %d", &m, &n);
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
    }
  solve(lu, 1, 1);
  solve(ld, -1, 1);
  solve(ru, 1, -1);
  solve(rd, -1, -1);
  int ans = 0;
  for (int i = 2; i < m; i++)
    for (int j = 2; j < n; j++) {
      ans = max(ans, lu[i - 1][j] + ld[i][j - 1] + ru[i][j + 1] + rd[i + 1][j]);
      ans = max(ans, lu[i][j - 1] + ld[i + 1][j] + ru[i - 1][j] + rd[i][j + 1]);
    }
  cout << ans;
  return 0;
}
