#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
long long dp1[1005][1005], dp2[1005][1005], dp3[1005][1005], dp4[1005][1005];
int main() {
  int n, m, i, j;
  long long ans = -1;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      dp1[i][j] = max(dp1[i][j - 1], dp1[i - 1][j]) + a[i][j];
  for (i = n; i > 0; i--)
    for (j = m; j > 0; j--)
      dp2[i][j] = max(dp2[i][j + 1], dp2[i + 1][j]) + a[i][j];
  for (i = n; i > 0; i--)
    for (j = 1; j <= m; j++)
      dp3[i][j] = max(dp3[i][j - 1], dp3[i + 1][j]) + a[i][j];
  for (i = 1; i <= n; i++)
    for (j = m; j > 0; j--)
      dp4[i][j] = max(dp4[i][j + 1], dp4[i - 1][j]) + a[i][j];
  for (i = 2; i < n; i++)
    for (j = 2; j < m; j++)
      ans = max(max(ans, dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] +
                             dp4[i][j + 1]),
                dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j]);
  printf("%I64d\n", ans);
  return 0;
}
