```
int m = grid.size(), n = grid[0].size();
vector<int> curV(m+1, INT_MAX);
curV[0] = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
curV[j+1] = grid[j][i]+min(curV[j+1], curV[j]);
curV[0] = curV[1];
}
}
return curV[m];
```