```
public int calculateMinimumHP(int[][] d) {
int[] h = new int[d[0].length];
for (int i = d.length - 1; i >= 0; i--) for (int j = d[0].length - 1; j >= 0; j--) h[j] = Math.max(1, Math.min(i == d.length - 1 ? Integer.MAX_VALUE : h[j], j == h.length - 1 ? (i == d.length - 1 ? 1 : Integer.MAX_VALUE) : h[j + 1]) - d[i][j]);
return h[0];
}
```