#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int INF = -1e9;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  long long dp[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i == 0 && j == 0)
        dp[i][j] = a[i][j];
      else {
        dp[i][j] =
            max((i >= 1 ? dp[i - 1][j] : INF), (j >= 1 ? dp[i][j - 1] : INF)) +
            +a[i][j];
      }
    }
  }
  long long dp2[n][m];
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if (i == n - 1 && j == m - 1) {
        dp2[i][j] = a[i][j];
      } else {
        dp2[i][j] = a[i][j] + max((i + 1 < n ? dp2[i + 1][j] : INF),
                                  (j + 1 < m ? dp2[i][j + 1] : INF));
      }
    }
  }
  long long dp3[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = m - 1; j >= 0; --j) {
      if (i == 0 && j == m - 1)
        dp3[i][j] = a[i][j];
      else {
        dp3[i][j] = a[i][j] + max((i > 0 ? dp3[i - 1][j] : INF),
                                  (j + 1 < m ? dp3[i][j + 1] : INF));
      }
    }
  }
  long long dp4[n][m];
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < m; ++j) {
      if (i == n - 1 && j == 0)
        dp4[i][j] = a[i][j];
      else {
        dp4[i][j] = a[i][j] + max((i + 1 < n ? dp4[i + 1][j] : INF),
                                  (j > 0 ? dp4[i][j - 1] : INF));
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    for (int j = 1; j < m - 1; ++j) {
      ans = max(ans,
                dp[i - 1][j] + dp4[i][j - 1] + dp2[i + 1][j] + dp3[i][j + 1]);
      ans = max(ans,
                dp[i][j - 1] + dp4[i + 1][j] + dp3[i - 1][j] + dp2[i][j + 1]);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
