#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 23;
const int MOD = 1e8;
const int N = 1e3 + 100;
const int M = 1e3 + 100;
int arr[N][M];
int best[4][N][M];
int n, m;
void go(int sti, int stj, int pi, int pj, int k) {
  for (int i = sti, r = 0; r < n; i += pi, ++r) {
    for (int j = stj, c = 0; c < m; j += pj, ++c) {
      best[k][i][j] = arr[i][j];
      int a1 = best[k][i - pi][j];
      int a2 = best[k][i][j - pj];
      best[k][i][j] += max(a1, a2);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = (1); i < (n + 1); ++i)
    for (int j = (1); j < (m + 1); ++j) cin >> arr[i][j];
  go(1, 1, 1, 1, 0);
  go(n, 1, -1, 1, 1);
  go(1, m, 1, -1, 2);
  go(n, m, -1, -1, 3);
  int ans = 0;
  for (int i = (2); i < (n); ++i)
    for (int j = (2); j < (m); ++j) {
      int a1 = best[0][i - 1][j] + best[3][i + 1][j];
      a1 += best[1][i][j - 1] + best[2][i][j + 1];
      ans = max(ans, a1);
      int a2 = best[0][i][j - 1] + best[3][i][j + 1];
      a2 += best[1][i + 1][j] + best[2][i - 1][j];
      ans = max(ans, a2);
    }
  cout << ans << "\n";
  return 0;
}
