#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <queue>
#include <memory.h>
#include <iostream>
#include <stack>
#include <complex>
#include <list>
using namespace std;
void ASS(bool bb)
{
if (!bb)
{
++*(int*)0;
}
}
#define FOR(i, x) for (int i = 0; i < (int)(x); ++i)
#define CL(x) memset(x, 0, sizeof(x))
#define CLX(x, y) memset(x, y, sizeof(x))
typedef vector<int> vi;
#pragma comment(linker, "/STACK:106777216")
const int inf = 1 << 30;
const int N = 107;
int n, m;
int a[N][N];
int d[N][N][N][2];
int D(int x, int L, int R, int moveRight)
{
if (x == n) {
if (L == R - 1 && R == m - 1)
return 0;
else
return -inf;
}
int &res = d[x][L][R][moveRight];
if (res != -1)
return res;
res = D(x + 1, L, R, 0) + a[x][L] + a[x][R]; // move both paths down
if (!moveRight) {
res = max(res, D(x, L, R, 1)); // stop moving left path, now move only right
if (L + 1 < R)
res = max(res, D(x, L + 1, R, 0) + a[x][L]); // move left path by one cell
} else {
if (R + 1 < m)
res = max(res, D(x, L, R + 1, 1) + a[x][R]); // move right path by one cell
}
return res;
}
int main() {
cin >> n >> m;
FOR(i, n) {
FOR(j, m) {
cin >> a[i][j];
}
}
memset(d, 0xFF, sizeof(d));
int res = D(0, 0, 1, 0);
cout << res << endl;
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19ERVBSRUNBVEUKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxxdWV1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