n = int(input()) input_list = [] for i in range(n): input_list.append(list(input().split())) amount = 0 for e in input_list: down_h, down_m = map(int, str(e[0]).split(':')) up_h, up_m = map(int, str(e[1]).split(':')) sleep_m = up_m - down_m sleep_h = up_h - down_h if sleep_h == 0 and sleep_m < 0: sleep_h += 24 if sleep_h < 0: sleep_h += 24 if sleep_m < 0: sleep_h -= 1 sleep_m += 60 if sleep_m >= 60: sleep_h += 1 sleep_m -= 60 amount += (sleep_h * 60) + sleep_m print(amount)