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)%24*60+(m-M) print(sum(sleep_time(input()) for i in range(int(input()))))