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

def absolute(d, h, m):
  return d*24*60 + h*60 + m

if x == 1:
  ans = absolute(24, 24, 0) - absolute(d, h, m)
elif x == 2:
  ans = absolute(25, 24, 0) - absolute(d, h, m)
elif x == 3:
  ans = absolute(26, 24, 0) - absolute(d, h, m)
elif x == 4:
  ans = absolute(27, 24, 0) - absolute(d, h, m)
else:
  ans = absolute(29, 24, 0) - absolute(d, h, m)
  if absolute(d, h, m) <= absolute(29, 2, 0):
    ans -= 60

print(ans)