#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long N = 100000;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
long long dp1[1002][1002];
long long dp2[1002][1002];
long long dp3[1002][1002];
long long dp4[1002][1002];
long long grid[1002][1002];
long long n, m;
map<pair<long long, long long>, bool> visit;
long long solve(long long i, long long j, long long ti, long long tj) {
  if (i == ti and j == tj) {
    dp1[i][j] = grid[i][j];
    return grid[i][j];
  }
  if (visit[{i, j}]) {
    return dp1[i][j];
  }
  long long pos1 = 0;
  long long pos2 = 0;
  if (i + 1 <= n) {
    pos1 = solve(i + 1, j, ti, tj);
  }
  if (j + 1 <= m) {
    pos2 = solve(i, j + 1, ti, tj);
  }
  dp1[i][j] = grid[i][j] + max(pos1, pos2);
  visit[{i, j}] = 1;
  return dp1[i][j];
}
long long solve2(long long i, long long j, long long ti, long long tj) {
  if (i == ti and j == tj) {
    dp2[i][j] = grid[i][j];
    return grid[i][j];
  }
  if (visit[{i, j}]) {
    return dp2[i][j];
  }
  long long pos1 = 0;
  long long pos2 = 0;
  if (i - 1 >= 1) {
    pos1 = solve2(i - 1, j, ti, tj);
  }
  if (j + 1 <= m) {
    pos2 = solve2(i, j + 1, ti, tj);
  }
  dp2[i][j] = grid[i][j] + max(pos1, pos2);
  visit[{i, j}] = 1;
  return dp2[i][j];
}
long long solve3(long long i, long long j, long long ti, long long tj) {
  if (i == ti and j == tj) {
    dp3[i][j] = grid[i][j];
    return grid[i][j];
  }
  if (visit[{i, j}]) {
    return dp3[i][j];
  }
  long long pos1 = 0;
  long long pos2 = 0;
  if (i - 1 >= 1) {
    pos1 = solve3(i - 1, j, ti, tj);
  }
  if (j - 1 >= 1) {
    pos2 = solve3(i, j - 1, ti, tj);
  }
  dp3[i][j] = grid[i][j] + max(pos1, pos2);
  visit[{i, j}] = 1;
  return dp3[i][j];
}
long long solve4(long long i, long long j, long long ti, long long tj) {
  if (i == ti and j == tj) {
    dp4[i][j] = grid[i][j];
    return grid[i][j];
  }
  if (visit[{i, j}]) {
    return dp4[i][j];
  }
  long long pos1 = 0;
  long long pos2 = 0;
  if (i + 1 <= n) {
    pos1 = solve4(i + 1, j, ti, tj);
  }
  if (j - 1 >= 1) {
    pos2 = solve4(i, j - 1, ti, tj);
  }
  dp4[i][j] = grid[i][j] + max(pos1, pos2);
  visit[{i, j}] = 1;
  return dp4[i][j];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> grid[i + 1][j + 1];
    }
  }
  memset(dp1, 0, sizeof dp1);
  memset(dp2, 0, sizeof dp2);
  memset(dp3, 0, sizeof dp3);
  memset(dp4, 0, sizeof dp4);
  solve(1, 1, n, m);
  visit.clear();
  solve2(n, 1, 1, m);
  visit.clear();
  solve3(n, m, 1, 1);
  visit.clear();
  solve4(1, m, n, 1);
  visit.clear();
  long long res = 0;
  for (long long i = 2; i <= n - 1; i++) {
    for (long long j = 2; j <= m - 1; j++) {
      if ((i == 1 and j == 1) or (i == n and j == 1) or (i == n and j == m) or
          (i == 1 and j == m))
        continue;
      long long pos1 =
          dp3[i - 1][j] + dp1[i + 1][j] + dp4[i][j - 1] + dp2[i][j + 1];
      long long pos2 =
          dp3[i][j - 1] + dp1[i][j + 1] + dp4[i + 1][j] + dp2[i - 1][j];
      long long cur = max(pos1, pos2);
      res = max(res, cur);
    }
  }
  cout << res << "\n";
  return 0;
}
