#include <bits/stdc++.h>
using namespace std;
int n, m, a[1010][1010];
int ul[1010][1010], ur[1010][1010], dl[1010][1010], dr[1010][1010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      ul[i][j] = max(ul[i - 1][j], ul[i][j - 1]) + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = m; j; j--)
      ur[i][j] = max(ur[i - 1][j], ur[i][j + 1]) + a[i][j];
  for (int i = n; i; i--)
    for (int j = 1; j <= m; j++)
      dl[i][j] = max(dl[i + 1][j], dl[i][j - 1]) + a[i][j];
  for (int i = n; i; i--)
    for (int j = m; j; j--)
      dr[i][j] = max(dr[i + 1][j], dr[i][j + 1]) + a[i][j];
  int ans = 0;
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++)
      ans = max(ans, ul[i][j - 1] + ur[i - 1][j] + dl[i + 1][j] + dr[i][j + 1]);
  for (int i = 2; i < n; i++)
    for (int j = 2; j < m; j++)
      ans = max(ans, dl[i][j - 1] + ul[i - 1][j] + dr[i + 1][j] + ur[i][j + 1]);
  cout << ans << endl;
  return 0;
}
