1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
input = sys.stdin.readline

# Round deadlines (effectively midnight of next day after stated 23:59:59)
# Round x -> (end_day, 0, 0)
deadlines = {
    1: (25, 0, 0),
    2: (26, 0, 0),
    3: (27, 0, 0),
    4: (28, 0, 0),
    5: (30, 0, 0),
}

def to_real(d, h, m):
    t = (d - 23) * 1440 + h * 60 + m
    # DST: March 29 at 2:00 -> 3:00 (1 hour lost)
    if d > 29 or (d == 29 and h >= 3):
        t -= 60
    return t

x, d, h, m = map(int, input().split())
ed, eh, em = deadlines[x]
print(max(to_real(ed, eh, em) - to_real(d, h, m), 0))