map int input split int for in input split for in range for in range m

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
n, m = map(int, input().split())
l = [[int(i) for i in input().split()] for _ in range(n)]
for c in range(m-2, -1, -1):
l[-1][c] += l[-1][c+1]
for r in range(n-2, -1, -1):
l[r][-1] += l[r+1][-1]
for r in range(n-2, -1, -1):
for c in range(m-2, -1, -1):
l[r][c] += min(l[r+1][c], l[r][c+1])
print(l[0][0])