#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  long long mat[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  }
  long long dp1[n][m], dp2[n][m], dp3[n][m], dp4[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (i == 0 && j == 0) {
        dp1[0][0] = mat[0][0];
      } else if (i == 0) {
        dp1[i][j] = dp1[i][j - 1] + mat[i][j];
      } else if (j == 0) {
        dp1[i][j] = dp1[i - 1][j] + mat[i][j];
      } else {
        dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + mat[i][j];
      }
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = m - 1; j >= 0; j--) {
      if (i == n - 1 && j == m - 1) {
        dp2[i][j] = mat[i][j];
      } else if (i == n - 1) {
        dp2[i][j] = dp2[i][j + 1] + mat[i][j];
      } else if (j == m - 1) {
        dp2[i][j] = dp2[i + 1][j] + mat[i][j];
      } else {
        dp2[i][j] = max(dp2[i + 1][j], dp2[i][j + 1]) + mat[i][j];
      }
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = 0; j < m; j++) {
      if (i == n - 1 && j == 0) {
        dp3[i][j] = mat[i][j];
      } else if (i == n - 1) {
        dp3[i][j] = dp3[i][j - 1] + mat[i][j];
      } else if (j == 0) {
        dp3[i][j] = dp3[i + 1][j] + mat[i][j];
      } else {
        dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + mat[i][j];
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = m - 1; j >= 0; j--) {
      if (i == 0 && j == m - 1) {
        dp4[i][j] = mat[i][j];
      } else if (i == 0) {
        dp4[i][j] = dp4[i][j + 1] + mat[i][j];
      } else if (j == m - 1) {
        dp4[i][j] = dp4[i - 1][j] + mat[i][j];
      } else {
        dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + mat[i][j];
      }
    }
  }
  long long mx = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (i == 0 || j == 0 || j == m - 1 || i == n - 1) {
        continue;
      }
      mx = max(mx,
               dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j]);
      mx = max(mx,
               dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]);
    }
  }
  cout << mx << endl;
}
