n = int(input()) sum = 0 for i in range(n): a, b = input().split() H, M = map(int, a.split(":")) h, m = map(int, b.split(":")) time = h-H if time < 0: time = 24 + time time = time * 60 + (m - M) sum+=time time = 0 print(sum)