#include <bits/stdc++.h>
using namespace std;
inline void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int dp[4][1003][1003];
long long int gr[1003][1003];
void dij(int i, int u, int v, int x, int y, int n, int m) {
  set<pair<long long int, pair<long long int, long long int>>,
      greater<pair<long long int, pair<long long int, long long int>>>>
      s;
  dp[i][u][v] = gr[u][v];
  s.insert(make_pair(dp[i][u][v], make_pair(u, v)));
  while (!s.empty()) {
    pair<long long int, pair<long long int, long long int>> p = *(s.begin());
    s.erase(s.begin());
    long long int d = p.first;
    long long int xx = p.second.first;
    long long int yy = p.second.second;
    if (xx > n || yy > m || xx < 1 || yy < 1) continue;
    if (0 < xx + x <= n && 0 < yy <= m) {
      if (d + gr[xx + x][yy] > dp[i][xx + x][yy]) {
        dp[i][xx + x][yy] = gr[xx + x][yy] + d;
        s.insert(make_pair(dp[i][xx + x][yy], make_pair(xx + x, yy)));
      }
    }
    if (0 < yy + y <= m && 0 < xx <= n) {
      if (d + gr[xx][yy + y] > dp[i][xx][yy + y]) {
        dp[i][xx][yy + y] = gr[xx][yy + y] + d;
        s.insert(make_pair(dp[i][xx][yy + y], make_pair(xx, yy + y)));
      }
    }
  }
}
int main() {
  fast();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> gr[i][j];
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      dp[0][i][j] = gr[i][j] + max(dp[0][i - 1][j], dp[0][i][j - 1]);
  for (int j = m; j >= 1; --j)
    for (int i = 1; i <= n; ++i)
      dp[1][i][j] = gr[i][j] + max(dp[1][i - 1][j], dp[1][i][j + 1]);
  for (int i = n; i >= 1; --i)
    for (int j = 1; j <= m; ++j)
      dp[2][i][j] = gr[i][j] + max(dp[2][i + 1][j], dp[2][i][j - 1]);
  for (int i = n; i >= 1; --i)
    for (int j = m; j >= 1; --j)
      dp[3][i][j] = gr[i][j] + max(dp[3][i][j + 1], dp[3][i + 1][j]);
  long long int mx = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j > 1 && j < m && i > 1 && i < m) {
        long long int d1 = dp[2][i][j - 1] + dp[1][i][j + 1];
        long long int d2 = dp[0][i - 1][j] + dp[3][i + 1][j];
        d1 += d2;
        mx = max(mx, d1);
      }
      if (i > 1 && i < n && j > 1 && j < m) {
        long long int d1 = dp[2][i + 1][j] + dp[1][i - 1][j];
        long long int d2 = dp[0][i][j - 1] + dp[3][i][j + 1];
        d1 += d2;
        mx = max(mx, d1);
      }
    }
  }
  cout << mx;
}
