#include <bits/stdc++.h>
using namespace std;
long long memo[4][1001][1001];
long long mp[1001][1001];
int n, m;
long long REC(int x, int y, int st) {
  if (x >= n || y >= m || x < 0 || y < 0) return 0;
  if (st == 0 && x == n - 1 && y == m - 1) return mp[x][y];
  if (st == 1 && x == 0 && y == 0) return mp[x][y];
  if (st == 2 && x == 0 && y == m - 1) return mp[x][y];
  if (st == 3 && x == n - 1 && y == 0) return mp[x][y];
  if (~memo[st][x][y]) return memo[st][x][y];
  long long a, b;
  if (st == 0) {
    a = REC(x + 1, y, st) + mp[x][y];
    b = REC(x, y + 1, st) + mp[x][y];
    return memo[st][x][y] = a >= b ? a : b;
  } else if (st == 1) {
    a = REC(x - 1, y, st) + mp[x][y];
    b = REC(x, y - 1, st) + mp[x][y];
    return memo[st][x][y] = a >= b ? a : b;
  } else if (st == 2) {
    a = REC(x - 1, y, st) + mp[x][y];
    b = REC(x, y + 1, st) + mp[x][y];
    return memo[st][x][y] = a >= b ? a : b;
  } else if (st == 3) {
    a = REC(x + 1, y, st) + mp[x][y];
    b = REC(x, y - 1, st) + mp[x][y];
    return memo[st][x][y] = a >= b ? a : b;
  }
}
long long check(int x, int y) {
  long long a, b, aa, bb, res = 0, tmp;
  b = memo[3][x + 1][y];
  a = memo[1][x][y - 1];
  bb = memo[2][x - 1][y];
  aa = memo[0][x][y + 1];
  tmp = aa + bb + a + b;
  res = tmp >= res ? tmp : res;
  b = memo[3][x][y - 1];
  a = memo[1][x - 1][y];
  bb = memo[2][x][y + 1];
  aa = memo[0][x + 1][y];
  tmp = aa + bb + a + b;
  res = tmp >= res ? tmp : res;
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mp[i][j];
    }
  }
  memset(memo, -1, sizeof memo);
  REC(0, 0, 0);
  REC(n - 1, m - 1, 1);
  REC(n - 1, 0, 2);
  REC(0, m - 1, 3);
  long long maxi = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      long long tmp = check(i, j);
      maxi = tmp >= maxi ? tmp : maxi;
    }
  }
  cout << maxi << endl;
  return 0;
}
