1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x,d,h,m = [int(x) for x in input().split()]

start = d*24*60+h*60+m

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

end = ENDS[x-1]*24*60+23*60+60

t = end-start

time_change = 29*24*60+2*60+0

if end>time_change and start<time_change:
    t-=60

print(t)