#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const bool debug = true;
const long long INFL = LLONG_MAX;
const int output_precision = 15;
stringstream ss;
int N, M, table[1010][1010];
long long memo[1010][1010][3][3];
bool was[1010][1010][3][3];
long long dp(int x, int y, int dx, int dy) {
  if (x <= 0 || y <= 0 || x > N || y > M) return -INF;
  if ((x == 1 || x == N) && (y == 1 || y == M)) return table[x][y];
  if (was[x][y][dx][dy]) return memo[x][y][dx][dy];
  was[x][y][dx][dy] = 1;
  long long& d = memo[x][y][dx][dy];
  d = -INF;
  d = max(d, dp(x + dx, y, dx, dy));
  d = max(d, dp(x, y + dy, dx, dy));
  d += table[x][y];
  return d;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(output_precision);
  cout << fixed;
  ss.precision(output_precision);
  ss << fixed;
  cin >> N >> M;
  for (int(i) = 1; (i) <= (N); (i)++)
    for (int(j) = 1; (j) <= (M); (j)++) cin >> table[i][j];
  long long ans = -INF;
  for (int(i) = 1; (i) <= (N); (i)++)
    for (int(j) = 1; (j) <= (M); (j)++) {
      long long acc = 0;
      acc += dp(i - 1, j, -1, -1);
      acc += dp(i + 1, j, 1, 1);
      acc += dp(i, j - 1, 1, -1);
      acc += dp(i, j + 1, -1, 1);
      ans = max(ans, acc);
    }
  for (int(i) = 1; (i) <= (N); (i)++)
    for (int(j) = 1; (j) <= (M); (j)++) {
      long long acc = 0;
      acc += dp(i - 1, j, -1, 1);
      acc += dp(i + 1, j, 1, -1);
      acc += dp(i, j - 1, -1, -1);
      acc += dp(i, j + 1, 1, 1);
      ans = max(ans, acc);
    }
  cout << ans << '\n';
}
