#include <bits/stdc++.h>
using namespace std;
int x8[] = {1, 1, 1, 0, 0, -1, -1, -1};
int y8[] = {1, 0, -1, 1, -1, -1, 0, -1};
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
long long int mod = 1e9 + 7;
int n, m;
long long int dp1[1000][1000];
long long int dp2[1000][1000];
long long int dp3[1000][1000];
long long int dp4[1000][1000];
long long int getvalue(int type, int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) {
    return 0;
  }
  if (type == 1) {
    return dp1[i][j];
  } else if (type == 2) {
    return dp2[i][j];
  } else if (type == 3) {
    return dp3[i][j];
  }
  return dp4[i][j];
}
void getac() {
  cin >> n >> m;
  long long int arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp1[i][j] = 0;
      dp2[i][j] = 0;
      dp3[i][j] = 0;
      dp4[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 && j == 0) {
        dp1[i][j] = arr[i][j];
      } else {
        if (i == 0) {
          dp1[i][j] = dp1[i][j - 1] + arr[i][j];
        } else if (j == 0) {
          dp1[i][j] = dp1[i - 1][j] + arr[i][j];
        } else {
          dp1[i][j] = max(dp1[i - 1][j], dp1[i][j - 1]) + arr[i][j];
        }
      }
    }
  }
  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] = arr[i][j];
      } else {
        if (i == n - 1) {
          dp2[i][j] = dp2[i][j + 1] + arr[i][j];
        } else if (j == m - 1) {
          dp2[i][j] = dp2[i + 1][j] + arr[i][j];
        } else {
          dp2[i][j] = max(dp2[i + 1][j], dp2[i][j + 1]) + arr[i][j];
        }
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      if (i == n - 1 && j == 0) {
        dp3[i][j] = arr[i][j];
      } else {
        if (i == n - 1) {
          dp3[i][j] = dp3[i][j - 1] + arr[i][j];
        } else if (j == 0) {
          dp3[i][j] = dp3[i + 1][j] + arr[i][j];
        } else {
          dp3[i][j] = max(dp3[i + 1][j], dp3[i][j - 1]) + arr[i][j];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      if (i == 0 && j == m - 1) {
        dp4[i][j] = arr[i][j];
      } else {
        if (i == 0) {
          dp4[i][j] = dp4[i][j + 1] + arr[i][j];
        } else if (j == m - 1) {
          dp4[i][j] = dp4[i - 1][j] + arr[i][j];
        } else {
          dp4[i][j] = max(dp4[i - 1][j], dp4[i][j + 1]) + arr[i][j];
        }
      }
    }
  }
  long long int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      ans = max(ans,
                dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]);
      ans = max(ans,
                dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j]);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    getac();
  }
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
