def main(): N = int(input()) T = tuple(tuple(input().split()) for _ in [0] * N) minutes = 0 for t1, t2 in T: h1, m1 = map(int, t1.split(':')) h2, m2 = map(int, t2.split(':')) m = (h2 * 60 + m2) - (h1 * 60 + m1) if m <= 0: minutes += m + 24 * 60 else: minutes += m print(minutes) main()