#include <bits/stdc++.h>
using namespace std;
const int INF = -1e9;
int n, m;
int a[1010][1010] = {0};
int way[1010][1010][4] = {0};
void compute_way(int xs, int ys, int dim, int xadd, int yadd) {
  int xf = xs + (n - 1) * xadd;
  int yf = ys + (m - 1) * yadd;
  int x, y;
  for (x = xs; x != xf + xadd; x += xadd) {
    for (y = ys; y != yf + yadd; y += yadd) {
      way[x][y][dim] =
          max(way[x - xadd][y][dim] + a[x][y], way[x][y - yadd][dim] + a[x][y]);
    }
  }
  for (x = 0; x <= n + 1; ++x) {
    way[x][0][dim] = way[x][m + 1][dim] = INF;
  }
  for (y = 0; y <= m + 1; ++y) {
    way[0][y][dim] = way[n + 1][y][dim] = INF;
  }
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i <= n + 1; ++i) {
    a[i][0] = a[i][m + 1] = INF;
  }
  for (j = 0; j <= m + 1; ++j) {
    a[0][j] = a[n + 1][j] = INF;
  }
  a[0][1] = a[1][0] = a[n][0] = a[n + 1][1] = a[0][m] = a[1][m + 1] =
      a[n][m + 1] = a[n + 1][m] = 0;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  compute_way(1, 1, 0, 1, 1);
  compute_way(1, m, 1, 1, -1);
  compute_way(n, 1, 2, -1, 1);
  compute_way(n, m, 3, -1, -1);
  int max_ans = 0;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      int cur_ans = way[i][j - 1][0] + way[i][j + 1][3] + way[i + 1][j][2] +
                    way[i - 1][j][1];
      max_ans = max(max_ans, cur_ans);
      cur_ans = way[i - 1][j][0] + way[i + 1][j][3] + way[i][j - 1][2] +
                way[i][j + 1][1];
      max_ans = max(max_ans, cur_ans);
    }
  }
  printf("%d\n", max_ans);
  return 0;
}
