#include #include #include using namespace std; int main(){ int h, w; cin >> h >> w; vector s(h); for(auto &it: s) cin >> it; vector> dp(h, vector(w, "{}")); dp[h-1][w-1] = s[h-1][w-1]; for(int i = h-1; i >= 0; i--){ for(int j = w-1; j >= 0; j--){ if(i+1 < h) dp[i][j] = min(dp[i][j], s[i][j]+dp[i+1][j]); if(j+1 < w) dp[i][j] = min(dp[i][j], s[i][j]+dp[i][j+1]); } } cout << dp[0][0] << endl; return 0; }