#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int N = 1001;
const int dx[] = {-1, 1, 1, -1};
const int dy[] = {-1, 1, -1, 1};
int dp[2][4][N][N];
int outx[4], outy[4];
int n, m;
int arr[N][N];
void dfs(int a, int b, int dir) {
  if (a >= n || a < 0 || b >= m || b < 0) return;
  if (dp[0][dir][a][b] != -1) return;
  dp[0][dir][a][b] = 0;
  dp[1][dir][a][b] = 0;
  int nx = a + dx[dir];
  int ny = b + dy[dir];
  dfs(nx, b, dir);
  dfs(a, ny, dir);
  if (nx >= 0 && nx < n) {
    dp[0][dir][a][b] = max(dp[0][dir][a][b], dp[0][dir][nx][b] + arr[nx][b]);
    dp[0][dir][a][b] = max(dp[0][dir][a][b], dp[1][dir][nx][b] + arr[nx][b]);
  }
  if (ny >= 0 && ny < m) {
    dp[1][dir][a][b] = max(dp[1][dir][a][b], dp[1][dir][a][ny] + arr[a][ny]);
    dp[1][dir][a][b] = max(dp[1][dir][a][b], dp[0][dir][a][ny] + arr[a][ny]);
  }
}
int main() {
  int i, j;
  cin >> n >> m;
  outx[0] = n - 1;
  outy[0] = m - 1;
  outx[1] = 0;
  outy[1] = 0;
  outx[2] = 0;
  outy[2] = m - 1;
  outx[3] = n - 1;
  outy[3] = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      scanf("%d", &arr[i][j]);
      for (int x = 0; x < 4; x++)
        for (int x2 = 0; x2 < 2; x2++) dp[x2][x][i][j] = -1;
    }
  for (i = 0; i < 4; i++) dfs(outx[i], outy[i], i);
  int ma = 0;
  for (i = 1; i < (n - 1); i++)
    for (j = 1; j < (m - 1); j++) {
      int cnt = 0;
      cnt = max(cnt, dp[0][0][i][j] + dp[1][2][i][j] + dp[0][1][i][j] +
                         dp[1][3][i][j]);
      cnt = max(cnt, dp[1][0][i][j] + dp[0][2][i][j] + dp[1][1][i][j] +
                         dp[0][3][i][j]);
      ma = max(ma, cnt);
    }
  cout << ma << endl;
}
