#include using namespace std; const vector dx = {0, 1, 1, 1}; const vector dy = {1, 0, 1, -1}; int main() { int h, w; cin >> h >> w; vector> A(h, vector(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> A[i][j]; } } vector> start; start.push_back(make_tuple(0, 0, 2)); for (int i = 1; i <= w; i++) { start.push_back(make_tuple(0, i, 1)); start.push_back(make_tuple(0, i, 2)); start.push_back(make_tuple(0, i, 3)); } start.push_back(make_tuple(0, w + 1, 3)); for (int i = 1; i <= h; i++) { start.push_back(make_tuple(i, 0, 0)); start.push_back(make_tuple(i, 0, 2)); start.push_back(make_tuple(i, 0, 3)); } long long ans = 0; for (tuple T1 : start) { for (tuple T2 : start) { long long res = 0; int x1, y1, d1, x2, y2, d2; tie(x1, y1, d1) = T1; tie(x2, y2, d2) = T2; x1 += dx[d1]; y1 += dy[d1]; x2 += dx[d2]; y2 += dy[d2]; set> st; while (1 <= x1 && x1 <= h && 1 <= y1 && y1 <= w) { res += A[x1 - 1][y1 - 1]; st.insert(make_pair(x1, y1)); x1 += dx[d1]; y1 += dy[d1]; } while (1 <= x2 && x2 <= h && 1 <= y2 && y2 <= w) { if (!st.count(make_pair(x2, y2))) { res += A[x2 - 1][y2 - 1]; } x2 += dx[d2]; y2 += dy[d2]; } ans = max(ans, res); } } cout << ans << endl; }