'''

def calculateMinimumHP(self, A):

x=len(A);

y=len(A[0]);

m=[[-121312 for i in range(y)] for j in range(x)];

#val,m=self.dynagohome(A,0,0,m,x,y);

for i in range(x-1,-1,-1):

for j in range(y-1,-1,-1):

if i!=x-1 and j!=y-1:

m[i][j]=min(A[i][j],A[i][j]+max(m[i+1][j],m[i][j+1]));

elif i==x-1 and j==y-1:

m[i][j]=A[i][j];

elif i==x-1:

m[i][j]=min(A[i][j],A[i][j]+m[i][j+1]);

else:

m[i][j]=min(A[i][j],A[i][j]+m[i+1][j]);

return max(1-m[0][0],1);

'''