
Fax McClad, Croneria's hungriest bounty hunter, wants to cook a quick meal in his microwave. Unfortunately, some of the buttons on his microwave have broken down.
Fax wants to microwave his food for hh:mm:ss
, where hh
is a 2 digit number representing the number of hours, mm
is a 2 digit number representing minutes, and ss
is a 2 digit number representing seconds. Note that mm
and ss
do not necessarily have to be less than
For reference, there are
The list of usable buttons will be given in a string as input. There will be at least one usable button.
Can you tell Fax the closest time that can be inputted to his desired time? That is, tell him the time with the smallest time difference that can be inputted in the microwave. Note that all digits (including zeroes) of the inputted time must be present in the string of working buttons.
Input Specification
The first line of input will contain Fax's desired time in the form hh:mm:ss
.
The second line of input will contain a string of at least
Output Specification
Output the closest time in hh:mm:ss
format that can be inputted in the microwave to Fax's desired time.
If there is more than one answer, output any of them.
Sample Input 1
01:17:27
012345689
Sample Output 1
01:16:86
Explanation for Sample Output 1
Fax wants to microwave his food for 7
.
A 01:16:86
are allowed, and this time results in 01:16:88
.
Sample Input 2
57:41:26
03578
Sample Output 2
57:38:88
Comments