#include <bits/stdc++.h>
#define pi acos(-1)
using namespace std;
int a[1005][1005];
bool vm[1005][1005];
bool vi[1005][1005];
int mi[1005][1005];
int maxn = -1;
int n, m, cnt;
void dfs(int x, int y){
if (x > n) return;
if (y > m) return;
if (x < 1) return;
if (y < 1) return;
if (vi[x][y] == true) return;
vi[x][y] = true;
mi[x][y] = cnt;
if (vm[x + 1][y] == false){
cnt += a[x + 1][y];
vm[x + 1][y] = true;
}
if (vm[x][y + 1] == false){
cnt += a[x][y + 1];
vm[x][y + 1] = true;
}
dfs(x + 1, y);
dfs(x, y + 1);
cnt -= a[x + 1][y];
cnt -= a[x][y + 1];
vm[x][y + 1] = false;
vm[x + 1][y] = false;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j){
cin >> a[i][j];
}
}
cnt = 0;
dfs(1, 1);
cout << mi[n][m] << endl;
}