#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int mp[maxn][maxn], n, m;
long long dp1[maxn][maxn][2], dp2[maxn][maxn][2], dp3[maxn][maxn][2],
    dp4[maxn][maxn][2];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &mp[i][j]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp1[i][j][0] = max(dp1[i][j - 1][0], dp1[i][j - 1][1]) + mp[i][j];
      dp1[i][j][1] = max(dp1[i - 1][j][0], dp1[i - 1][j][1]) + mp[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      dp2[i][j][0] = max(dp2[i][j + 1][0], dp2[i][j + 1][1]) + mp[i][j];
      dp2[i][j][1] = max(dp2[i + 1][j][0], dp2[i + 1][j][1]) + mp[i][j];
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++) {
      dp3[i][j][0] = max(dp3[i][j - 1][0], dp3[i][j - 1][1]) + mp[i][j];
      dp3[i][j][1] = max(dp3[i + 1][j][0], dp3[i + 1][j][1]) + mp[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j >= 1; j--) {
      dp4[i][j][0] = max(dp4[i][j + 1][0], dp4[i][j + 1][1]) + mp[i][j];
      dp4[i][j][1] = max(dp4[i - 1][j][0], dp4[i - 1][j][1]) + mp[i][j];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 || i == n || j == 1 || j == m) continue;
      ans = max(dp1[i][j][0] + dp2[i][j][0] + dp3[i][j][1] + dp4[i][j][1] -
                    4 * mp[i][j],
                ans);
      ans = max(dp1[i][j][1] + dp2[i][j][1] + dp3[i][j][0] + dp4[i][j][0] -
                    4 * mp[i][j],
                ans);
    }
  }
  cout << ans << endl;
}
