There are plenty of guided activities in a certain swimming pool. Therefore, the usage rules are very strict:
The free time slots are only one minute long.
After using a free slot, we must wait for at least seconds before using another slot.
You have the list of free slots, and you want to swim for at least minutes. What is the maximum that allows it?
Input consists of several cases. Every case begins with the number of minutes and the number of slots , followed by triples ::, indicating that there is a lane that is free for one minute starting at ::. Assume , that the hours are between :: and ::, and that there are no overlaps between time slots. The final entry is marked with a special case with .
For every case, print the maximum that permits a total bath time of or more minutes.
Input
2 2 00:00:00 00:01:00 2 2 00:00:00 00:10:03 2 3 10:10:00 00:10:00 00:20:00 3 4 23:00:00 22:00:00 21:00:00 20:00:00 4 8 00:10:40 00:35:30 01:00:00 01:55:00 02:10:00 03:15:00 12:00:20 23:59:00 0 0
Output
0 543 35940 3540 11000