#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long int arr[n][m];
  long int dp1[n][m];
  long int dp2[n][m];
  long int dp3[n][m];
  long int dp4[n][m];
  long int workout = 0;
  long int left, right;
  long int hot;
  for (long int i = 0; i < n; ++i) {
    for (long int j = 0; j < m; ++j) {
      cin >> arr[i][j];
    }
  }
  for (long int i = 0; i < n; ++i) {
    for (long int j = 0; j < m; ++j) {
      if (i > 0 && j > 0)
        dp1[i][j] = arr[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]);
      else if (i == 0 && j == 0) {
        dp1[i][j] = arr[i][j];
      } else if (i == 0) {
        dp1[i][j] = arr[i][j] + dp1[i][j - 1];
      } else
        dp1[i][j] = arr[i][j] + dp1[i - 1][j];
    }
  }
  for (long int i = 0; i < n; ++i) {
    for (long int j = m - 1; j >= 0; --j) {
      if (i > 0 && j < m - 1)
        dp2[i][j] = arr[i][j] + max(dp2[i - 1][j], dp2[i][j + 1]);
      else if (i == 0 && j == m - 1) {
        dp2[i][j] = arr[i][j];
      } else if (i == 0)
        dp2[i][j] = arr[i][j] + dp2[i][j + 1];
      else
        dp2[i][j] = arr[i][j] + dp2[i - 1][j];
    }
  }
  for (long int i = n - 1; i >= 0; --i) {
    for (long int j = 0; j < m; ++j) {
      if (i < n - 1 && j > 0)
        dp3[i][j] = arr[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]);
      else if (i == n - 1 && j == 0) {
        dp3[i][j] = arr[i][j];
      } else if (i == n - 1)
        dp3[i][j] = arr[i][j] + dp3[i][j - 1];
      else
        dp3[i][j] = arr[i][j] + dp3[i + 1][j];
    }
  }
  for (long int i = n - 1; i >= 0; --i) {
    for (long int j = m - 1; j >= 0; --j) {
      if (j < m - 1 && i < n - 1)
        dp4[i][j] = arr[i][j] + max(dp4[i + 1][j], dp4[i][j + 1]);
      else if (i == n - 1 && j == m - 1) {
        dp4[i][j] = arr[i][j];
      } else if (i == n - 1) {
        dp4[i][j] = arr[i][j] + dp4[i][j + 1];
      } else
        dp4[i][j] = arr[i][j] + dp4[i + 1][j];
    }
  }
  for (long int i = 1; i < n - 1; ++i) {
    for (long int j = 1; j < m - 1; ++j) {
      left = dp1[i][j - 1] + dp4[i][j + 1] + dp3[i + 1][j] + dp2[i - 1][j];
      right = dp1[i - 1][j] + dp4[i + 1][j] + dp3[i][j - 1] + dp2[i][j + 1];
      hot = max(left, right);
      if (hot > workout) workout = hot;
    }
  }
  cout << workout << "\n";
}
