N = int(input()) minutes_total = 0 for i in range(N): time_get_up, time_go_to_bed = [s for s in input().split()] hours_go_to_bed, minutes_go_to_bed = [int(i) for i in time_get_up.split(':')] hours_get_up, minutes_get_up = [int(i) for i in time_go_to_bed.split(':')] converted_go_to_bed = hours_go_to_bed * 60 + minutes_go_to_bed converted_get_up = hours_get_up * 60 + minutes_get_up if converted_go_to_bed > converted_get_up: converted_get_up += 24 * 60 minutes_total += converted_get_up - converted_go_to_bed print(minutes_total)