#include <bits/stdc++.h>
using namespace std;
long long int a[1004][1003], v[1003][1004], y[1003][1004], w[1004][1004],
    t[1004][1004];
int main() {
  int n, m;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  }
  queue<pair<long, long> > q;
  pair<long, long> l;
  l.first = 1;
  l.second = 1;
  q.push(l);
  while (!q.empty()) {
    pair<long, long> e = q.front();
    q.pop();
    long long int h = v[e.first - 1][e.second];
    long long int p = v[e.first][e.second - 1];
    if (h > p) p = h;
    v[e.first][e.second] = a[e.first][e.second] + p;
    if (e.first + 1 <= n && v[e.first + 1][e.second] == 0) {
      v[e.first + 1][e.second] = 1;
      l.first = e.first + 1;
      l.second = e.second;
      q.push(l);
    }
    if (e.second + 1 <= m && v[e.first][e.second + 1] == 0) {
      v[e.first][e.second + 1] = 1;
      l.first = e.first;
      l.second = e.second + 1;
      q.push(l);
    }
  }
  l.first = n;
  l.second = 1;
  q.push(l);
  while (!q.empty()) {
    pair<long, long> e = q.front();
    q.pop();
    long h = w[e.first + 1][e.second];
    long p = w[e.first][e.second - 1];
    if (h > p) p = h;
    w[e.first][e.second] = a[e.first][e.second] + p;
    if (e.first - 1 >= 1 && w[e.first - 1][e.second] == 0) {
      w[e.first - 1][e.second] = 1;
      l.first = e.first - 1;
      l.second = e.second;
      q.push(l);
    }
    if (e.second + 1 <= m && w[e.first][e.second + 1] == 0) {
      w[e.first][e.second + 1] = 1;
      l.first = e.first;
      l.second = e.second + 1;
      q.push(l);
    }
  }
  l.first = 1;
  l.second = m;
  q.push(l);
  while (!q.empty()) {
    pair<long, long> e = q.front();
    q.pop();
    long h = t[e.first - 1][e.second];
    long p = t[e.first][e.second + 1];
    if (h > p) p = h;
    t[e.first][e.second] = a[e.first][e.second] + p;
    if (e.first + 1 <= n && t[e.first + 1][e.second] == 0) {
      t[e.first + 1][e.second] = 1;
      l.first = e.first + 1;
      l.second = e.second;
      q.push(l);
    }
    if (e.second - 1 >= 1 && t[e.first][e.second - 1] == 0) {
      t[e.first][e.second - 1] = 1;
      l.first = e.first;
      l.second = e.second - 1;
      q.push(l);
    }
  }
  l.first = n;
  l.second = m;
  q.push(l);
  while (!q.empty()) {
    pair<long, long> e = q.front();
    q.pop();
    long h = y[e.first + 1][e.second];
    long p = y[e.first][e.second + 1];
    if (h > p) p = h;
    y[e.first][e.second] = a[e.first][e.second] + p;
    if (e.first - 1 >= 1 && y[e.first - 1][e.second] == 0) {
      y[e.first - 1][e.second] = 1;
      l.first = e.first - 1;
      l.second = e.second;
      q.push(l);
    }
    if (e.second - 1 >= 1 && y[e.first][e.second - 1] == 0) {
      y[e.first][e.second - 1] = 1;
      l.first = e.first;
      l.second = e.second - 1;
      q.push(l);
    }
  }
  long long int mo = 0;
  for (long i = 1; i <= n; i++) {
    for (long j = 1; j <= m; j++) {
      long long int h = v[i][j - 1] + y[i][j + 1] + w[i + 1][j] + t[i - 1][j];
      long long int f = v[i - 1][j] + y[i + 1][j] + t[i][j + 1] + w[i][j - 1];
      if (h > mo && i - 1 >= 1 && i + 1 <= n && j - 1 >= 1 && j + 1 <= m)
        mo = h;
      if (f > mo && i - 1 >= 1 && i + 1 <= n && j - 1 >= 1 && j + 1 <= m)
        mo = f;
    }
  }
  cout << mo << endl;
}
