def sleep_time(s: str): HM, hm = s.split() H, M = map(int, HM.split(':')) h, m = map(int, hm.split(':')) return ((h-H+24)*60+(m-M)+1440)%1440 print(sum(sleep_time(input()) for i in range(int(input()))))