#include <bits/stdc++.h>
using namespace std;
const long long oo = 2e15;
const int N = 1e3;
int n, m, a[N][N];
long long dp[N][N][4];
long long calc1(int x, int y) {
  if (x == n - 1 && y == m - 1) return dp[x][y][0] = a[x][y];
  if (x == n || y == m) return -oo;
  long long &res = dp[x][y][0];
  if (res != -1) return res;
  return res = a[x][y] + max(calc1(x + 1, y), calc1(x, y + 1));
}
long long calc2(int x, int y) {
  if (x == 0 && y == 0) return dp[x][y][1] = a[x][y];
  if (x < 0 || y < 0) return -oo;
  long long &res = dp[x][y][1];
  if (res != -1) return res;
  return res = a[x][y] + max(calc2(x - 1, y), calc2(x, y - 1));
}
long long calc3(int x, int y) {
  if (x == 0 && y == m - 1) return dp[x][y][2] = a[x][y];
  if (x < 0 || y == m) return -oo;
  long long &res = dp[x][y][2];
  if (res != -1) return res;
  return res = a[x][y] + max(calc3(x - 1, y), calc3(x, y + 1));
}
long long calc4(int x, int y) {
  if (x == n - 1 && y == 0) return dp[x][y][3] = a[x][y];
  if (x == n || y < 0) return -oo;
  long long &res = dp[x][y][3];
  if (res != -1) return res;
  return res = a[x][y] + max(calc4(x + 1, y), calc4(x, y - 1));
}
long long get(int x, int y) {
  long long r1 = 0, r2 = 0;
  r1 += calc2(x, y - 1) + calc4(x + 1, y);
  r1 += calc1(x, y + 1) + calc3(x - 1, y);
  r2 += calc2(x - 1, y) + calc4(x, y - 1);
  r2 += calc1(x + 1, y) + calc3(x, y + 1);
  return max(r1, r2);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
      dp[i][j][0] = dp[i][j][1] = dp[i][j][2] = dp[i][j][3] = -1;
    }
  calc1(0, 0);
  calc2(n - 1, m - 1);
  calc3(n - 1, 0);
  calc4(0, m - 1);
  long long res = 0;
  for (int i = 1; i < n - 1; ++i)
    for (int j = 1; j < m - 1; ++j) res = max(res, get(i, j));
  printf("%lld\n", res);
  return 0;
}
