1
2
3
4
5
6
7
8
9
x, d, h, m = map(int, input().split())

rounds = [24, 25, 26, 27, 29]

time = (rounds[x-1] - d) * 24 * 60 + 23 * 60 + 60 - h * 60 - m
if x == 5 and (h < 3 or d < 29):
    time -= 60

print(time)