#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int dp1[1005][1005];
long long int dp2[1005][1005];
long long int dp3[1005][1005];
long long int dp4[1005][1005];
long long int board[1005][1005];
void topLeft() {
  for (long long int i = 0; i < m; i++) {
    for (long long int j = 0; j < n; j++) {
      if (i == 0 && j == 0)
        dp1[i][j] = board[i][j];
      else if (i == 0)
        dp1[i][j] = dp1[i][j - 1] + board[i][j];
      else if (j == 0)
        dp1[i][j] = dp1[i - 1][j] + board[i][j];
      else
        dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + board[i][j];
    }
  }
}
void bottomLeft() {
  for (long long int i = m - 1; i >= 0; i--) {
    for (long long int j = 0; j < n; j++) {
      if (i == m - 1 && j == 0)
        dp2[i][j] = board[i][j];
      else if (i == m - 1)
        dp2[i][j] = dp2[i][j - 1] + board[i][j];
      else if (j == 0)
        dp2[i][j] = dp2[i + 1][j] + board[i][j];
      else
        dp2[i][j] = max(dp2[i + 1][j], dp2[i][j - 1]) + board[i][j];
    }
  }
}
void bottomRight() {
  for (long long int i = m - 1; i >= 0; i--) {
    for (long long int j = n - 1; j >= 0; j--) {
      if (i == m - 1 && j == n - 1)
        dp3[i][j] = board[i][j];
      else if (i == m - 1)
        dp3[i][j] = dp3[i][j + 1] + board[i][j];
      else if (j == n - 1)
        dp3[i][j] = dp3[i + 1][j] + board[i][j];
      else
        dp3[i][j] = max(dp3[i + 1][j], dp3[i][j + 1]) + board[i][j];
    }
  }
}
void topRight() {
  for (long long int i = 0; i < m; i++) {
    for (long long int j = n - 1; j >= 0; j--) {
      if (i == 0 && j == n - 1)
        dp4[i][j] = board[i][j];
      else if (i == 0)
        dp4[i][j] = dp4[i][j + 1] + board[i][j];
      else if (j == n - 1)
        dp4[i][j] = dp4[i - 1][j] + board[i][j];
      else
        dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + board[i][j];
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> m >> n;
  for (long long int i = 0; i < m; i++)
    for (long long int j = 0; j < n; j++) cin >> board[i][j];
  topLeft();
  bottomLeft();
  bottomRight();
  topRight();
  long long int ans = 0;
  for (long long int i = 1; i < m - 1; i++) {
    for (long long int j = 1; j < n - 1; j++) {
      long long int case1 =
          dp1[i - 1][j] + dp2[i][j - 1] + dp3[i + 1][j] + dp4[i][j + 1];
      long long int case2 =
          dp1[i][j - 1] + dp2[i + 1][j] + dp3[i][j + 1] + dp4[i - 1][j];
      ans = max(ans, max(case1, case2));
    }
  }
  cout << ans;
  return 0;
}
