n = int(input())

t = 0
for i in range(n):
    inp = list(map(int, input().replace(':', ' ').split()))
    start = inp[0]*60 + inp[1]
    end = inp[2]*60 + inp[3]
    if start <= end:
        t += (end-start)
    else:
        t += (end + 24*60 - start)
print(t)