#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  long long ip[n + 10][m + 10];
  long long dp1[n + 10][m + 10];
  long long dp2[n + 10][m + 10];
  long long dp3[n + 10][m + 10];
  long long dp4[n + 10][m + 10];
  long long answer = 0;
  for (long long i = 0; i < n + 10; i++) {
    for (long long j = 0; j < m + 10; j++) {
      dp1[i][j] = 0;
      dp2[i][j] = 0;
      dp3[i][j] = 0;
      dp4[i][j] = 0;
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      cin >> ip[i][j];
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + ip[i][j];
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = m; j >= 1; j--) {
      dp2[i][j] = max(dp2[i - 1][j], dp2[i][j + 1]) + ip[i][j];
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = 1; j < m + 1; j++) {
      dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + ip[i][j];
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      dp4[i][j] = max(dp4[i + 1][j], dp4[i][j + 1]) + ip[i][j];
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (i == 1 || i == n || j == 1 || j == m) {
        continue;
      }
      answer = max(answer, dp1[i - 1][j] + dp4[i + 1][j] + dp3[i][j - 1] +
                               dp2[i][j + 1]);
      answer = max(answer, dp1[i][j - 1] + dp4[i][j + 1] + dp3[i + 1][j] +
                               dp2[i - 1][j]);
    }
  }
  cout << answer;
  return 0;
}
