def sleep(H, M, h, m): if H > h or (H == h and M > m): h += 24 return h * 60 + m - H * 60 - M N = int(input()) total = 0 for n in range(N): HM, hm = input().split() H, M = map(int, HM.split(':')) h, m = map(int, hm.split(':')) total += sleep(H, M, h, m) print(total)