#include <bits/stdc++.h>#define rep(i,a,b) for (int i = a; i<=b; ++i)usingnamespacestd;
constint nmax = 50;
constint INF = 0x3f3f3f3f;
typedeflonglong ll;
typedefdouble db;
int mp[nmax][nmax];
bool visit[nmax][nmax];
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
int n, m;
int ans = 0;
bool legal(int x, int y) {
if (x < 1 || x > n || y < 1 || y > m || visit[x][y] == true) returnfalse;
returntrue;
}
void dfs(int x, int y) {
visit[x][y] = 1; ans += mp[x][y];
// printf("debug %d %d\n",x,y);if (x == n && y == m) return;
int nx = -1, ny = -1, cnt = 0;
for (int i = 0; i < 4; ++i) {
int ntx = x + xx[i];
int nty = y + yy[i];
if (legal(ntx, nty)) {
if (mp[ntx][nty] > cnt) {
nx = ntx;
ny = nty;
cnt = mp[ntx][nty];
}
}
}
if (x == -1 && y == -1) return;
dfs(nx, ny);
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
scanf("%d", &mp[i][j]);
}
}
dfs(1, 1);
printf("%d\n", ans);
return0;
}