We have an ATM on which there are 10 buttons to enter each digit and one button to…
- User
We have an ATM on which there are 10 buttons to enter each digit and one button to delete the rightmost digit of the entered number.
We want with this device, the number n Enter n. But we know that the 10 digit buttons of this device are broken, but the delete button works properly.
Description of the image
We have understood the problem of the device and we know that if the button d Enter d, string s d s d (in the same order) enters the device. We are also sure that the first digit of the string s d s d self d d is It is possible s d s d Include repeated digits.
Now we want you to press the least number of buttons to enter the number n Calculate n is required.
input In the first line, enter a positive integer n n is given. 1 ≤ n ≤ 1 0 1000 1≤n≤10 1000
In the next 10 lines in the line d dam field s d s d has come 1 ≤ ∣ s d ∣ ≤ 10 1≤∣s d ∣≤10 It is guaranteed that the first digit s d s d self d It is d, but it is possible s d s d have a duplicate digit.
output In a single output line, the minimum number of operations required to enter a number n Write n.
examples Sample entry 1 140102 0 1 2 3 4 5 6 7 8 9 Plain text Sample output 1 6 Plain text Explanation of sample 1 Sample input 2 18415 0 15 2 3 415 59 6 7 84 9 Plain text Sample output 2 4 Plain text Explanation of sample 2 Sample entry 3 18415 0 16 2 3 415 59 6 7 84 9 Plain text Sample output 3 5 c++
- Assistant