1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import sys


def to_real_minutes(d: int, h: int, m: int) -> int:
	mins = ((d - 23) * 24 + h) * 60 + m
	if d > 29 or (d == 29 and h >= 3):
		mins -= 60
	return mins

x, d, h, m = map(int, sys.stdin.readline().split())
end_day = [0, 24, 25, 26, 27, 29][x]
start = to_real_minutes(d, h, m)
end_ex = to_real_minutes(end_day + 1, 0, 0)
print(end_ex - start)