n = int(input()) total_sleep = 0 for i in range(n): time = input().split() sleep_h = int(time[0].split(":")[0]) sleep_m = int(time[0].split(":")[1]) wake_up_h = int(time[1].split(":")[0]) wake_up_m = int(time[1].split(":")[1]) if sleep_h > wake_up_h: wake_up_h += 24 total_sleep += wake_up_h * 60 + wake_up_m - sleep_h * 60 - sleep_m print(total_sleep)