#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> vec(1001, vector<int>(1000));
int dp1[1001][1001];
int dp2[1001][1001];
int dp3[1001][1001];
int dp4[1001][1001];
int solve1(int i, int j) {
  if (dp1[i][j] != -1) return dp1[i][j];
  if (i == n - 1 && j == m - 1) {
    return dp1[i][j] = vec[i][j];
  }
  if (j == m - 1) {
    return dp1[i][j] = (vec[i][j] + solve1(i + 1, j));
  }
  if (i == n - 1) {
    return dp1[i][j] = (vec[i][j] + solve1(i, j + 1));
  }
  int ans1 = 0;
  return dp1[i][j] = (vec[i][j] + max(solve1(i + 1, j), solve1(i, j + 1)));
}
int solve2(int i, int j) {
  if (dp2[i][j] != -1) return dp2[i][j];
  if (i == 0 && j == 0) {
    return dp2[i][j] = vec[i][j];
  }
  if (j == 0) {
    return dp2[i][j] = (vec[i][j] + solve2(i - 1, j));
  }
  if (i == 0) {
    return dp2[i][j] = (vec[i][j] + solve2(i, j - 1));
  }
  int ans1 = 0;
  return dp2[i][j] = (vec[i][j] + max(solve2(i - 1, j), solve2(i, j - 1)));
}
int solve3(int i, int j) {
  if (dp3[i][j] != -1) return dp3[i][j];
  if (i == 0 && j == m - 1) {
    return dp3[i][j] = vec[i][j];
  }
  if (j == m - 1) {
    return dp3[i][j] = (vec[i][j] + solve3(i - 1, j));
  }
  if (i == 0) {
    return dp3[i][j] = (vec[i][j] + solve3(i, j + 1));
  }
  int ans1 = 0;
  return dp3[i][j] = (vec[i][j] + max(solve3(i - 1, j), solve3(i, j + 1)));
}
int solve4(int i, int j) {
  if (dp4[i][j] != -1) return dp4[i][j];
  if (i == n - 1 && j == 0) {
    return dp4[i][j] = vec[i][j];
  }
  if (j == 0) {
    return dp4[i][j] = (vec[i][j] + solve4(i + 1, j));
  }
  if (i == n - 1) {
    return dp4[i][j] = (vec[i][j] + solve4(i, j - 1));
  }
  int ans1 = 0;
  return dp4[i][j] = (vec[i][j] + max(solve4(i + 1, j), solve4(i, j - 1)));
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (1001); ++i) {
    for (int j = 0; j < (1001); ++j) {
      dp1[i][j] = dp2[i][j] = dp3[i][j] = dp4[i][j] = -1;
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      cin >> vec[i][j];
    }
  }
  int ans2 = solve1(0, 0);
  ans2 = solve2(n - 1, m - 1);
  ans2 = solve3(n - 1, 0);
  ans2 = solve4(0, m - 1);
  ans2 = 0;
  for (int i = 1; i <= (n - 2); ++i) {
    for (int j = 1; j <= (m - 2); ++j) {
      ans2 = max(ans2,
                 dp2[i - 1][j] + dp1[i + 1][j] + dp4[i][j - 1] + dp3[i][j + 1]);
      ans2 = max(ans2,
                 dp3[i - 1][j] + dp4[i + 1][j] + dp2[i][j - 1] + dp1[i][j + 1]);
    }
  }
  cout << ans2 << "\n";
}
