Author:  Антон Карабанов  Time limit:  1 sec  
Input file:  Standard input  Memory limit:  512 Mb  
Output file:  Standard output 
Zhenya Slavin is a first human born on Mars. He is yet a little boy and likes to look at the digital clock hanging opposite of his bed. Most of all he likes the moments when all digits on the clock become identical. In those moments he always claps joyfully.
Since the period of rotation of Mars around its axis is different from that of the Earth, Martian colonists decided that:
Current time on Mars is h_{M} hours, m_{M} minutes and s_{M} seconds. After how many seconds will Zhenya clap? Time on the Martian digital clocks is displayed with leading zeroes in all positions. Extra positions are not used.
Input contains six integers, one per line: h, m and s — description of Martian day subdivision, followed by h_{M}, m_{M} and s_{M} — current time.
Output a single integer — number of seconds until the moment when all digits on the clock become identical.
0 ≤ h_{M} < h ≤ 10^{6}
0 ≤ m_{M} < m ≤ 10^{6}
0 ≤ s_{M} < s ≤ 10^{6}
It the first sample Martian days are no different from Earth ones (24 hours of 60 minutes of 60 seconds). Now it is 23 hours 50 minutes exactly (clock displays digits 23:50:00
). After 10 minutes (or 600 seconds) the clock will display zeroes in all positions.
It the second sample Martian days contain 627 hours of 5 minutes of 777 seconds. Now it is 49 hours 3 minutes and 2 seconds (clock displays digits 049:3:002
). After 61 hours 3 minutes and 109 seconds (or 239425 Martian seconds) the clock will display ones in all positions.
No.  Standard input  Standard output 

1 


2 

