Swimming pool (2)

There are plenty of guided activities in a certain swimming pool. Therefore, the usage rules are very strict:

You have the list of free slots, and you want to swim for at least mm minutes. What is the maximum xx that allows it?

Input

Input consists of several cases. Every case begins with the number of minutes mm and the number of slots nn, followed by nn triples HH:MM:SS, indicating that there is a lane that is free for one minute starting at HH:MM:SS. Assume 2mn10002 \le m \le n \le 1000, that the hours are between 0000:0000:0000 and 2323:5959:0000, and that there are no overlaps between time slots. The final entry is marked with a special case with m=n=0m = n = 0.

Output

For every case, print the maximum xx that permits a total bath time of mm or more minutes.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:14:28.662Z

© Jutge.org, 2006–2026.
https://jutge.org