#include <bits/stdc++.h>
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  unsigned long long dp1[n][m];
  dp1[0][0] = a[0][0];
  for (int j = 1; j < m; j++) {
    dp1[0][j] = a[0][j] + dp1[0][j - 1];
  }
  for (int i = 1; i < n; i++) {
    dp1[i][0] = a[i][0] + dp1[i - 1][0];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      dp1[i][j] = a[i][j] + std::max(dp1[i][j - 1], dp1[i - 1][j]);
    }
  }
  unsigned long long dp2[n][m];
  dp2[n - 1][0] = a[n - 1][0];
  for (int j = 1; j < m; j++) {
    dp2[n - 1][j] = a[n - 1][j] + dp2[n - 1][j - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    dp2[i][0] = a[i][0] + dp2[i + 1][0];
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 1; j < m; j++) {
      dp2[i][j] = a[i][j] + std::max(dp2[i][j - 1], dp2[i + 1][j]);
    }
  }
  unsigned long long dp3[n][m];
  dp3[0][m - 1] = a[0][m - 1];
  for (int j = m - 2; j >= 0; j--) {
    dp3[0][j] = a[0][j] + dp3[0][j + 1];
  }
  for (int i = 1; i < n; i++) {
    dp3[i][m - 1] = a[i][m - 1] + dp3[i - 1][m - 1];
  }
  for (int i = 1; i < n; i++) {
    for (int j = m - 2; j >= 0; j--) {
      dp3[i][j] = a[i][j] + std::max(dp3[i][j + 1], dp3[i - 1][j]);
    }
  }
  unsigned long long dp4[n][m];
  dp4[n - 1][m - 1] = a[n - 1][m - 1];
  for (int j = m - 2; j >= 0; j--) {
    dp4[n - 1][j] = a[n - 1][j] + dp4[n - 1][j + 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    dp4[i][m - 1] = a[i][m - 1] + dp4[i + 1][m - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = m - 2; j >= 0; j--) {
      dp4[i][j] = a[i][j] + std::max(dp4[i][j + 1], dp4[i + 1][j]);
    }
  }
  unsigned long long maxPath = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      maxPath = std::max(maxPath, dp1[i - 1][j] + dp2[i][j - 1] +
                                      dp3[i][j + 1] + dp4[i + 1][j]);
      maxPath = std::max(maxPath, dp1[i][j - 1] + dp2[i + 1][j] +
                                      dp3[i - 1][j] + dp4[i][j + 1]);
    }
  }
  printf("%llu", maxPath);
}
