#include <bits/stdc++.h>
long long MOD = 1000000007;
long long inf = 1e18;
using namespace std;
long long Mem[1001][1001][4][4];
long long n, m;
long long L[1001][1001];
long long Solve(long long i, long long j, long long d, long long f) {
  if (i < 0 || i >= n || j < 0 || j >= m) {
    return -1e17;
  }
  if (Mem[i][j][d][f] != -1) {
    return Mem[i][j][d][f];
  }
  long long ans = -1e17;
  long long move, x = -1e17;
  if (d == 0) {
    if (i == 0 && j == 0) {
      return L[0][0];
    }
    if (f != 2) ans = Solve(i - 1, j, d, 0);
    if (f != 1) x = Solve(i, j - 1, d, 0);
    if (x > ans) {
      ans = x;
    }
    if (ans != -1e17) {
      ans += L[i][j];
    }
    Mem[i][j][d][f] = ans;
    return Mem[i][j][d][f];
  }
  if (d == 1) {
    if (i == 0 && j == m - 1) {
      return L[i][j];
    }
    if (f != 2) ans = Solve(i, j + 1, d, 0);
    if (f != 1) x = Solve(i - 1, j, d, 0);
    if (x > ans) {
      ans = x;
    }
    if (ans != -1e14) {
      ans += L[i][j];
    }
    Mem[i][j][d][f] = ans;
    return Mem[i][j][d][f];
  }
  if (d == 2) {
    if (i == n - 1 && j == 0) {
      return L[i][j];
    }
    if (f != 2) ans = Solve(i, j - 1, d, 0);
    if (f != 1) x = Solve(i + 1, j, d, 0);
    if (x > ans) {
      ans = x;
    }
    if (ans != -1e17) {
      ans += L[i][j];
    }
    Mem[i][j][d][f] = ans;
    return Mem[i][j][d][f];
  }
  if (d == 3) {
    if (i == n - 1 && j == m - 1) {
      return L[i][j];
    }
    if (f != 2) ans = Solve(i, j + 1, d, 0);
    if (f != 1) x = Solve(i + 1, j, d, 0);
    if (x > ans) {
      ans = x;
    }
    if (ans != -1e17) {
      ans += L[i][j];
    }
    Mem[i][j][d][f] = ans;
    return Mem[i][j][d][f];
  }
}
int main() {
  cin >> n >> m;
  long long i, j, k, z;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> L[i][j];
      for (k = 0; k < 4; k++)
        for (z = 0; z < 3; z++) Mem[i][j][k][z] = -1;
    }
  }
  long long a, b;
  long long best = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (i == 0 && j == 0) {
        continue;
      }
      if (i == 0 && j == m - 1) {
        continue;
      }
      a = Solve(i, j, 0, 1) + Solve(i, j, 2, 1) + Solve(i, j, 3, 2) +
          Solve(i, j, 1, 1) - 4 * L[i][j];
      b = Solve(i, j, 0, 2) + Solve(i, j, 2, 2) + Solve(i, j, 3, 1) +
          Solve(i, j, 1, 2) - 4 * L[i][j];
      best = max(a, best);
      best = max(b, best);
    }
  }
  cout << best;
  return 0;
}
