def timetoint(s):
    h, s = [ int(v) for v in s.split(":") ]
    return 60*h+s


n = int(input())
total = 0
for i in range(n):
    t1, t2 = [ timetoint(v) for v in input().split() ]
    if t1 > t2:
        t2 += 1440
    total += (t2-t1)
print(total)