cho.sh
NotesCho Mini
Loading...

Amusement Park

Time limit

1s

Memory limit

128 MB

Problem

Sehyuk and Geunyeong work at an amusement park, each responsible for several rides, and they like each other. They want to use their breaks to spend time together. Before work starts each day, they look at that day's ride schedule and try to find the longest break they can share.

Park employees cannot rest from 10 minutes before any ride starts until 10 minutes after that ride stops. They may rest only during the remaining time inside the workday, which runs from 10:00 to 22:00.

Suppose three rides operate at the following times.

  • Ride 1: 10:30 - 13:00
  • Ride 2: 19:00 - 21:10
  • Ride 3: 12:30 - 16:50

In this situation, the two can rest together for 20 minutes before the first ride starts, for 1 hour and 50 minutes after the third ride ends and before the second ride starts, and for 40 minutes after the second ride ends. Therefore, their longest shared break is 1 hour and 50 minutes.

Given the ride schedule, write a program that finds the longest time Sehyuk and Geunyeong can rest together that day.

Input

The first line contains the number of rides, N. Each of the next N lines contains the start time and end time of one ride, separated by a space. Each time is written as four digits in HHMM format; for instance, 13:00 is written as 1300 and 22:00 is written as 2200. N is a positive integer not greater than 50.

Output

Print the longest time, in minutes, that Sehyuk and Geunyeong can rest together. If there is no time when they can rest together, print 0.