#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2020;
//const int MOD = 998244353;
ll dp[N][N];
int main(){
int n,m; cin >> n >> m;
for(int i=1 ; i <= n ; i++){
for(int j=1 ; j <= m ; j++){
cin >> dp[i][j];
}
}
for(int i=1 ; i <= n ; i++){
for(int j=1 ; j <= m ; j++){
if(i == 1){
dp[i][j] += dp[i][j-1];
}
else if(j == 1){
dp[i][j] += dp[i-1][j];
}
else{
dp[i][j] += min(dp[i-1][j],dp[i][j-1]);
}
}
}
cout << dp[n][m];
return 0;
}

京公网安备 11010502036488号