1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
a, b, h, m = map(int, input().split())
res = 0
if a != 5:
    if b == 23 + a:
        res = (24 - h - 1) * 60 + 60 - m
    else:
        res = (24 - h - 1) * 60 + 60 - m + 24 * 60
else:
    if b == 29:
        if h >= 3:
            res = (24 - h - 1) * 60 + 60 - m
        else:
            res = (24 - h - 1) * 60 - m
    elif b == 28:
        res = (24 - h - 1) * 60 + 60 - m + 23 * 60
    else:
        res = (24 - h - 1) * 60 + 60 - m + 47 * 60
print(res)