Use dynamic programming to solve the min path sum