#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int dx[4] = {1, 1, -1, -1};
const int dy[4] = {1, -1, -1, 1};
int n, m;
int t[MAXN + 2][MAXN + 2];
int dp[4][MAXN + 2][MAXN + 2];
int sol;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> t[i][j];
  for (int d = 0; d < 4; ++d)
    for (int i = dy[d] == 1 ? 1 : n; i && i <= n; i += dy[d])
      for (int j = dx[d] == 1 ? 1 : m; j && j <= m; j += dx[d])
        dp[d][i][j] = max(dp[d][i - dy[d]][j], dp[d][i][j - dx[d]]) + t[i][j];
  for (int i = 2; i < n; ++i)
    for (int j = 2; j < m; ++j)
      sol = max(sol, max(dp[0][i - 1][j] + dp[1][i][j - 1] + dp[2][i + 1][j] +
                             dp[3][i][j + 1],
                         dp[0][i][j - 1] + dp[1][i + 1][j] + dp[2][i][j + 1] +
                             dp[3][i - 1][j]));
  cout << sol << endl;
  return 0;
}
