#include <bits/stdc++.h>
using namespace std;
int arr[1005][1005], n, m, dp[1005][1005][4];
int dir[8][2] = {{-1, 0}, {0, -1}, {0, 1},  {1, 0},
                 {1, 0},  {0, -1}, {-1, 0}, {0, 1}};
int getdp(int x, int y, int i) {
  if (x < 1 || x > n) return 0;
  if (y < 1 || y > m) return 0;
  return dp[x][y][i];
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &arr[i][j]);
      }
    }
    dp[1][1][1] = arr[1][1];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (i == 1 && j == 1)
          continue;
        else if (i == 1)
          dp[i][j][1] = dp[i][j - 1][1] + arr[i][j];
        else if (j == 1)
          dp[i][j][1] = dp[i - 1][j][1] + arr[i][j];
        else
          dp[i][j][1] = max(dp[i][j - 1][1], dp[i - 1][j][1]) + arr[i][j];
      }
    }
    dp[n][m][2] = arr[n][m];
    for (int i = n; i >= 1; i--) {
      for (int j = m; j >= 1; j--) {
        if (i == n && j == m)
          continue;
        else if (i == n)
          dp[i][j][2] = dp[i][j + 1][2] + arr[i][j];
        else if (j == m)
          dp[i][j][2] = dp[i + 1][j][2] + arr[i][j];
        else
          dp[i][j][2] = max(dp[i][j + 1][2], dp[i + 1][j][2]) + arr[i][j];
      }
    }
    dp[n][1][3] = arr[n][1];
    for (int i = n; i >= 1; i--) {
      for (int j = 1; j <= m; j++) {
        if (i == n && j == 1)
          continue;
        else if (i == n)
          dp[i][j][3] = dp[i][j - 1][3] + arr[i][j];
        else if (j == 1)
          dp[i][j][3] = dp[i + 1][j][3] + arr[i][j];
        else
          dp[i][j][3] = max(dp[i][j - 1][3], dp[i + 1][j][3]) + arr[i][j];
      }
    }
    dp[1][m][0] = arr[1][m];
    for (int i = 1; i <= n; i++) {
      for (int j = m; j >= 1; j--) {
        if (i == 1 && j == m)
          continue;
        else if (i == 1)
          dp[i][j][0] = dp[i][j + 1][0] + arr[i][j];
        else if (j == m)
          dp[i][j][0] = dp[i - 1][j][0] + arr[i][j];
        else
          dp[i][j][0] = max(dp[i][j + 1][0], dp[i - 1][j][0]) + arr[i][j];
      }
    }
    int ans = 0;
    for (int i = 2; i <= n - 1; i++) {
      for (int j = 2; j <= m - 1; j++) {
        for (int a1 = 0; a1 <= 1; a1++) {
          for (int a2 = 2; a2 <= 3; a2++) {
            for (int a3 = 4; a3 <= 5; a3++) {
              for (int a4 = 6; a4 <= 7; a4++) {
                int x1 = dir[a1][0] + i;
                int y1 = dir[a1][1] + j;
                int x2 = dir[a2][0] + i;
                int y2 = dir[a2][1] + j;
                int x3 = dir[a3][0] + i;
                int y3 = dir[a3][1] + j;
                int x4 = dir[a4][0] + i;
                int y4 = dir[a4][1] + j;
                if (x1 == x3 && y1 == y3) continue;
                if (x1 == x4 && y1 == y4) continue;
                if (x2 == x4 && y2 == y4) continue;
                if (x2 == x3 && y2 == y3) continue;
                ans = max(getdp(x1, y1, 1) + getdp(x2, y2, 2) +
                              getdp(x3, y3, 3) + getdp(x4, y4, 0),
                          ans);
              }
            }
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
