#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
int n, m, arr[1010][1010];
long long int dp1[1010][1010], dp2[1010][1010], dp3[1010][1010],
    dp4[1010][1010];
long long int func4(int row, int column) {
  long long int temp1 = 0, temp2 = 0;
  if (dp4[row][column] != -1) return dp4[row][column];
  if (row == n && column == 1) {
    dp4[row][column] = arr[row][column];
    return arr[row][column];
  } else if (row == n + 1 || column == 0)
    return 0;
  else {
    temp1 += (arr[row][column] + func4(row + 1, column));
    temp2 += (arr[row][column] + func4(row, column - 1));
  }
  dp4[row][column] = ((temp1) > (temp2) ? (temp1) : (temp2));
  return dp4[row][column];
}
long long int func3(int row, int column) {
  long long int temp1 = 0, temp2 = 0;
  if (dp3[row][column] != -1) return dp3[row][column];
  if (row == 1 && column == 1) {
    dp3[row][column] = arr[row][column];
    return arr[row][column];
  } else if (row == 0 || column == 0)
    return 0;
  else {
    temp1 += (arr[row][column] + func3(row - 1, column));
    temp2 += (arr[row][column] + func3(row, column - 1));
  }
  dp3[row][column] = ((temp1) > (temp2) ? (temp1) : (temp2));
  return dp3[row][column];
}
long long int func2(int row, int column) {
  long long int temp1 = 0, temp2 = 0;
  if (dp2[row][column] != -1) return dp2[row][column];
  if (row == 1 && column == m) {
    dp2[row][column] = arr[row][column];
    return arr[row][column];
  } else if (row == 0 || column == m + 1)
    return 0;
  else {
    temp1 += (arr[row][column] + func2(row - 1, column));
    temp2 += (arr[row][column] + func2(row, column + 1));
  }
  dp2[row][column] = ((temp1) > (temp2) ? (temp1) : (temp2));
  return dp2[row][column];
}
long long int func1(int row, int column) {
  long long int temp1 = 0, temp2 = 0;
  if (dp1[row][column] != -1) return dp1[row][column];
  if (row == n && column == m) {
    dp1[row][column] = arr[row][column];
    return arr[row][column];
  } else if (row == n + 1 || column == m + 1)
    return 0;
  else {
    temp1 += (arr[row][column] + func1(row + 1, column));
    temp2 += (arr[row][column] + func1(row, column + 1));
  }
  dp1[row][column] = ((temp1) > (temp2) ? (temp1) : (temp2));
  return dp1[row][column];
}
int main() {
  ios::sync_with_stdio(false);
  long long int temp1, temp2, temp3, temp4, value1, value2, value = 0;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) cin >> arr[i][j];
  }
  memset(dp1, -1, sizeof(dp1));
  memset(dp2, -1, sizeof(dp2));
  memset(dp3, -1, sizeof(dp3));
  memset(dp4, -1, sizeof(dp4));
  temp1 = func1(1, 1);
  temp2 = func2(n, 1);
  temp3 = func3(n, m);
  temp4 = func4(1, m);
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      value1 = dp3[i - 1][j] + dp1[i + 1][j] + dp2[i][j + 1] + dp4[i][j - 1];
      value2 = dp3[i][j - 1] + dp1[i][j + 1] + dp2[i - 1][j] + dp4[i + 1][j];
      value = ((value) > (((value1) > (value2) ? (value1) : (value2)))
                   ? (value)
                   : (((value1) > (value2) ? (value1) : (value2))));
    }
  }
  cout << value;
  return 0;
}
