import re n = int(input()) time = [list(map(int,re.split(r"[:\s]",input()))) for _ in range(n)] total = 0 for t in time: if t[0] > t[2]: sleep = 1440 - (60*t[0]+t[1]) + (60*t[2]+t[3]) elif t[2] == 0 and t[3] == 0: sleep = 1440 - (60*t[0]+t[1]) else: sleep = (60*t[2]+t[3]) - (60*t[0]+t[1]) total += sleep print(total)