#include <bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int a[105][105];
int n,m;
struct pos{
int x,y,s,cost;
pos (int ax=0,int ay=0,int as=0,int acost=0){
x=ax,y=ay,s=as,cost=acost;
}
};
int s=inf,cost=inf;
queue<pos> q;
void bfs(){
q.push(pos(1,1,0,0));
while (!q.empty()){
pos now=q.front();
q.pop();
if (now.s>s) continue;
if (now.x<1||now.y<1||now.x>n||now.y>m) continue;
if (now.x==n&&now.y==m){
if (s>now.s) s=now.s,cost=now.cost;
else{
if (s==now.s){
if (cost>now.cost){
cost=now.cost;
}
}
}
}
now.cost+=a[now.x][now.y];
q.push(pos(now.x+1,now.y,now.s+1,now.cost));
q.push(pos(now.x,now.y+1,now.s+1,now.cost));
}
cout << cost+a[n][m];
return;
}
int main(){
cin >> n >> m;
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++){
cin >> a[i][j];
}
}
bfs();
}